Some suggestions for Android Oom and GC
Here's a nice article on analyzing memory leaks. It can definitely help you. Http://android-developers.blogspot.com/2011/03/memory-analysis-for-android.html.
Can you ensure that your softhashmap is working properly? Looks rather complicated. It is recommended to use debugger to ensure that there are never more than 15 bitmaps in Softhashmap. Mat can also help you determine how many bitmaps appear in memory. You can call cache.put (Phototoload.url, BMP) to disable the memory cache and determine whether there is a problem.
Activity leak If you're just sliding in the same activity to get oom, that means something else leaking instead of activity. If you stop/start the activity several times, you find that Oom still appears. Then check mat histogram to determine if activity leaking
When you use an image with a size that is not quite certain. It should be guaranteed to work perfectly, even with images as large as 5m px.
You can try to change the implementation of your SoftReference only with hashmap<string, softreference<bitmap>>. This is a good implementation in memory cache. It determines whether the object has enough memory in memory. If there is too little memory, the object SoftReference disposed.
I recommend using Linkedhashmap to process in-memory cache. It has a special construction iteration in which the last access order of the entry. The document says that when you have more than 15 items in the cache, you can delete the least recently accessed items.
If you want to load larger images, you should consider how much memory they are consuming. If too many, you can just cache their SD card instead of in memory. In doing so, performance may be slower, but not oom
Nothing to Oom. If you call ClearCache () in the Onlowmemory () method. This is not a good thing, because ClearCache () will also delete the SD cache, you know you have to do is to clear the memory cache instead of the SD cache
Analyze the heap, using the Jhat or Eclipse Memory Analyzer (MAT) tool
Hprof-conv dump.hprof Converted-dump.hprof
Resource here:
Here's an amazing article on analyzing memory leaks. It can definitely help you. Http://android-developers.blogspot.com/2011/03/memory-analysis-for-android.html.
Is you absolutely sure your SOFTHASHMAP implementation works fine? Looks rather complicated. You can use the debugger to ensure Softhashmap never holds more than. MAT can also help and identify how many bitmaps is there in memory.
You can also comment cache.put (Phototoload.url, BMP) call. This is the I-Disable in-memory caching to identify if it's a cause of a problem or not.
Yes It May is an Activity leak. You can identify that. If you just scroll around in the same activity and get OOM it means that something else was leaking not activity. If you stop/start activity several times and get OOM it means activity is leaking. Also You can definitely say are activity leaking or not if the a look at MAT histogram.
As you use insamplesize the image size doesn ' t matter. It should work fine even with 5mpx images.
you could try to replace your SOFTHASHMAP implementation with just hashmap<string, Softreference<bitmap >>. Read about SoftReference. It is good for very simple implementation of in-memory cache. It holds objects in memory if there ' s enough memory. If there ' s too little memory SoftReference releases objects.
I can also recommend you to use Linkedhashmap for In-memory cache. It has a special constuctor to iterate items in the order in which its entries were last accessed. So if you had more than the items in the cache you can remove least-recently accessed items. As documentation says:
You know my implementation is designed with small images on mind and something like 50*50. If you had larger images you should think how much memory they consume. If They take too much you could just cache them to SD card and not to memory. The performance may is slower but OOM would is a problem any more.
Not related to OOM. I can see the ClearCache () in Onlowmemory (). Not good because ClearCache () also removes cache from SD. You should only clear in-memory cache is not SD cache.
Some suggestions for Android Oom and GC