sakibguy / worked-issues

arget medi a[rpescriptionmedicie] &ssets[dr] (reeeverse._ax:p)
2 stars 0 forks source link

[ORG] SG-MYALICE: [PERF] Memory leak! #82

Closed sakibguy closed 1 year ago

sakibguy commented 1 year ago

PROB

 This error happens if you call setState() on a State object for a widget that no longer appears in the widget tree (e.g., whose parent widget no longer includes the widget in its build). This error can occur when code calls setState() from a timer or an animation callback.
E/flutter ( 8103): The preferred solution is to cancel the timer or stop listening to the animation in the dispose() callback. Another solution is to check the "mounted" property of this object before calling setState() to ensure the object is still in the tree.
E/flutter ( 8103): This error might indicate a memory leak if setState() is being called because another object is retaining a reference to this State object after it has been removed from the tree. To avoid memory leaks, consider breaking the reference to this object during dispose().
E/flutter ( 8103): #0      State.setState.<anonymous closure> (package:flutter/src/widgets/framework.dart:1078:9)
E/flutter ( 8103): #1      State.setState (package:flutter/src/widgets/framework.dart:1113:6)
E/flutter ( 8103): #2      _LinkableTextView.getPreviewData (package:myalice/screens/chatDetails/customWidgets/chats/linkableTextView.dart:82:5)
E/flutter ( 8103): <asynchronous suspension>

SNaP

Memory leak

Screenshot (269)

sakibguy commented 1 year ago

REASON

Potential reason: GetX not properly coded.

Potential soln: getx dependency injection https://www.youtube.com/playlist?list=PL8qudE8OCWVYRduM8mye7tXDSezdz7SVD

sakibguy commented 1 year ago

SOL 1

Commented setState() from catch block. setState() snippet not injected by myself so I didn't know the logical purpose of this snippet inside catch block. @snrahman01 apu could help better.

  double height = 0;
  String changedUrl = '';
  Future<void> getPreviewData(String url) async {
    try {
      if (url.contains('l.facebook.com')) {
        String delimiter1 = 'u=';
        String delimiter2 = '&h=';
        var n = Uri.decodeComponent(url);
        int firstIndex = n.indexOf(delimiter1) + 2;
        int lastIndex = n.indexOf(delimiter2);
        String trimmed = n.substring(firstIndex, lastIndex);
        changedUrl = trimmed;
        print(trimmed);
      } else
        changedUrl = url;
      data = await MetadataFetch.extract(changedUrl);
      if (data!.image != null) {
        Uri u = Uri.parse(changedUrl);
        var hostUrl = u.host;
        if (!data!.image!.startsWith('http')) {
          data!.image = 'http://' + hostUrl + data!.image!;
        }
      }
    } catch (e) {}

    // setState(() {});
  }

SNaP

stage 1 -> imu 1 imu 2

Screenshot (270)