lucasr / smoothie

[DEPRECATED] Easy async loading for Android's ListView/GridView
985 stars 163 forks source link

Runs out of Memory after switching from portrait to landscape orientation #22

Closed theoklink closed 10 years ago

theoklink commented 10 years ago

I have found that using the library, my Samsung Tab3 device runs out of memory when scrolling and switching to/from portrait/landscape. Initially the gridview is populated (with albumart) normally. Flinging up and down uses around 65 to 70Mb. and this level is fairly constant. However, once you have switched orientation, memory usage jumps up and quickly reaches over 90Mb after which the scrolling and refreshing becomes extremely slow. Finallly the app simply stops. (no ANR) I have taken the sample Gallery app, but instead of images, I display albumart. No other amendments were made. I have around 600 albums to display. ps tested with an earlier version but same behaviour

blundell commented 10 years ago

Nice to have the MAT report to show it is definitely this view holding onto the mem

theoklink commented 10 years ago

I would appreciate it If you can explain what a MAT report is and how I could get this. I am quite sure it is attributable to the library as I can repeat this issue consistently.

theoklink commented 10 years ago

Installed MAT but have no idea how to use it. User guides do not really help. There is no doubt that the memory issue is caused by the smoothie library.

Anyway, I have replaced the memory allocation in Gallery Loader with ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); int memoryClass = manager.getMemoryClass(); int memoryClassInKilobytes = memoryClass * 1024; int maxSize = memoryClassInKilobytes; Behaviour is better but still runs out of memory. I have not been able to find any code that would indicate the mMemCache is maintained. For instance, when deleting an item in the grid and after mGalleryAdapter.notifyDataSetChanged(), it seems that the memory cache is not updated immediately. I would appreciate some input

blundell commented 10 years ago

Sorry I forgot to reply, I highly recommend this video from Google IO it explains MAT and finding memory leaks http://www.youtube.com/watch?v=_CruQY55HOk

Android apps have more memory available to them than ever before, but are you sure you're using it wisely? This talk will cover the memory management changes in Gingerbread and Honeycomb (concurrent GC, heap-allocated bitmaps, "largeHeap" option) and explore tools and techniques for profiling the memory usage of Android apps.

theoklink commented 10 years ago

Paul many thanks. Very useful tutorial. I have learned about yet another useful area. I followed it through but can not discover any leaks. The only question I have is the use of "runnable" in the smoothie ItemLoader. The presenter mentions this specifically in the context of caching bitmaps and that you need to be aware as this may hold on to references for longer than desired. I have the leak hprof report but can not attach it so how can I make this available.