How to Navigator.push memory efficiently Flutter

Viewed 279

My app has screens that are fullscreen GridViews of NetworkImages, and every time you click an image it takes you to a new page with another GridView of images. I am running into memory issues and the app is crashing because every time I Navigator.push a new page, the images on the previous page are still held in memory, causing a memory leak. I need to keep the full history of pages, and users need to go back. Is there a way to have the images freed from memory when Navigator.push is called and have them be rebuilt when there is a Navigator.pop event? I've tried using CachedNetworkImage and OptimizedCachedImage but both cause even more memory issues.

Here is a gist displaying the issue: https://gist.github.com/Sofianel5/3b29e15024b902f6f04ce2f84598171c

1 Answers

Make sure you are Calling dispose function in every page

  @override
  void dispose(){
   super.dispose();
  }
Related