Skip to content

Improve Flutter's memory consumption #32156

Closed

Description

@cbracken

This is a tracking bug for the collection of sub-issues around improving Flutter's memory consumption, and offering developers more flexibility in choosing where to set the dial on the time performance vs memory consumption spectrum.

Related issues:

Activity

  1. added
    engineflutter/engine related. See also e: labels.
    c: performanceRelates to speed or footprint issues (see "perf:" labels)
    on May 6, 2019
  2. rsaf commented on May 16, 2019

    @rsaf

    This is a really worrying issue for many developers. I created a similar issue.

    #32820

  3. deverlion commented on Jul 24, 2019

    @deverlion

    We also have completely similar problems.We are now in v1.5.4-hotfix.2, the video plays normally, and iOS does not crash. But when I upgrade to v1.7.8+hotfix.3, iOS video playback is easy to crash because of iOS memory issues. (Only iOS has problems, Android is OK)

  4. DyaryRaoof commented on Oct 12, 2019

    @DyaryRaoof

    any solution guys ?

  5. alectogeek commented on Nov 9, 2019

    @alectogeek

    Is there any news? It really prevents us from releasing an app because it becomes too memory consuming because of a huge count of images in the app :(

  6. DyaryRaoof commented on Nov 9, 2019

    @DyaryRaoof

    @alectogeek
    Try changing to master channel and use the cacheWidth and cacheHeight parameters with your image widgets like so Image.Network(cacheWidth:100, cacheHeight : 100) or use it with Cached_Network_Image(cacheWidth:100, cacheHeight : 100).

    This is supposed prevent too much memory consumption.

    I haven't yet tested it because I have problem with changing to the master channel and there are errors preventing me from testing this. It may not be the same in your case. I use a lot of plugins wich maybe causing the issue that I haven't had time to find a solution for.

    Please let me know if the solution worked for you.

  7. alectogeek commented on Nov 9, 2019

    @alectogeek

    @DyaryRaoof Thank you for answer! But looks like cached_network_image 2.0.0-rc.1 package doesn't have cacheHeight/cacheWidth properties

  8. DyaryRaoof commented on Nov 9, 2019

    @DyaryRaoof

    @DyaryRaoof Thank you for answer! But looks like cached_network_image 2.0.0-rc.1 package doesn't have cacheHeight/cacheWidth properties

    It think it 's present if I am not mistaken. But did you try it in the Image.Network and see if it's present or not. because the last time I checked I couldn't find it either I had to install the flutter SDK again then switch to the master channel but I am not sure if it was present in the Cached_Network_image.

    And as a side note. why not try Image.Network with the cacheWidth and cacheHeight constructors if it is present . It may make your app a lot more stable.

  9. alectogeek commented on Nov 9, 2019

    @alectogeek

    @DyaryRaoof Unfortunately, I can't try this. I need to cache images in local storage so I use cached_network_image absolutely everywhere in my app. Moreover, I show almost the whole picture, so, I guess, it will not help in my case. :(

  10. added
    customer: crowdAffects or could affect many people, though not necessarily a specific customer.
    on Nov 11, 2019
  11. AAverin1994 commented on Nov 22, 2019

    @AAverin1994

    Any news? I am also having problems with memory leak. #45391

  12. Mohammad-Adam commented on Jan 24, 2020

    @Mohammad-Adam

    @DyaryRaoof Unfortunately, I can't try this. I need to cache images in local storage so I use cached_network_image absolutely everywhere in my app. Moreover, I show almost the whole picture, so, I guess, it will not help in my case. :(

    FutureBuilder<File>( initialData: File.fromRawPath(kTransparentImage), builder: (cx, file) { return Image.file( file.data, cacheWidth: 250, cacheHeight: 250, fit: BoxFit.contain, ); }, future: DefaultCacheManager() .downloadFile(widget.post.postImages[index]) .then((fileInfo) => fileInfo.file), );

    i'm facing this problem, and i'm using this code to use cacheWidth and cacheHeight with cache managing, using package:flutter_cache_manager: ^1.1.3

  13. davewise commented on Feb 5, 2020

    @davewise

    cacheHeight/cacheWidth properties fixed the massive memory usage in my case. I actually only use cacheWidth to maintain aspect. Even when I set the cacheWidth to 1200 the memory usage is 5 times smaller than without that property set. Seems like the cacheWidth should default to some reasonable number that doesn't cause memory hogging and can be overridden with a larger or smaller number if the developer wishes.

  14. danielgchap commented on Feb 10, 2020

    @danielgchap

    cacheHeight/cacheWidth properties fixed the massive memory usage in my case. I actually only use cacheWidth to maintain aspect. Even when I set the cacheWidth to 1200 the memory usage is 5 times smaller than without that property set. Seems like the cacheWidth should default to some reasonable number that doesn't cause memory hogging and can be overridden with a larger or smaller number if the developer wishes.

    Hi davewise! Are you using cachednetworkimage or the out of the box Image.network approach? (I'm currently using cachednetworkimage, I'm just trying to find the best approach)

  15. pacifio commented on Mar 8, 2020

    @pacifio

    It happens mostly when showing images ..

  16. liyuqian commented on Mar 23, 2020

    @liyuqian
    Contributor

    @dnfield : would you also prefer to close this meta issue and just track memory issues from label "perf: memory"? (Similar to what you've done with #13493)

  17. dnfield commented on Mar 23, 2020

    @dnfield
    Contributor

    I'm not a huge fan of meta issues like this - they tend to get outdated. And at least one of the linked issues in the top of this bug would actually increase memory consumption.

    I think before closing this one we should make sure the linked bugs are closed/addressed though. With the image cache one the bugs it referred to were all either out of date or closed.

  18. davewise commented on Apr 2, 2020

    @davewise

    cacheHeight/cacheWidth properties fixed the massive memory usage in my case. I actually only use cacheWidth to maintain aspect. Even when I set the cacheWidth to 1200 the memory usage is 5 times smaller than without that property set. Seems like the cacheWidth should default to some reasonable number that doesn't cause memory hogging and can be overridden with a larger or smaller number if the developer wishes.

    Hi davewise! Are you using cachednetworkimage or the out of the box Image.network approach? (I'm currently using cachednetworkimage, I'm just trying to find the best approach)

    I'm using the Image.network approach. Not sure which is the best approach though...

  19. ShekarMudaliyar commented on May 9, 2020

    @ShekarMudaliyar

    Any updates on this? my app is in production and want to send an update but cannot coz its crashing on ios

  20. dnfield commented on May 18, 2020

    @dnfield
    Contributor

    I've closed out a few of the bugs linked here that I believe are resolved. Some of them are still not, so I've made sure to label with with perf: memory. There are a number of other bugs related to memory under that tag, which should be the most up to date way of finding and tracking memory related issues.

    I'm going to close this issue since it is not really up to date and will quickly get out of date again if we add more bugs to it. Instead, follow perf: memory Performance issues related to memory

  21. github-actions commented on Aug 21, 2021

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  22. locked as resolved and limited conversation to collaborators on Aug 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    c: performanceRelates to speed or footprint issues (see "perf:" labels)customer: crowdAffects or could affect many people, though not necessarily a specific customer.engineflutter/engine related. See also e: labels.perf: memoryPerformance issues related to memory

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions