Some suggestions for Android Oom and GC

Source: Internet
Author: User

Some suggestions for Android Oom and GC


  1. 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.

  2. 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.

  3. 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

  4. 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.

  5. 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.

  6. 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.

  7. 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

  8. 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:

  1. 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.

  2. 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.

  3. 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.

  4. As you use insamplesize the image size doesn ' t matter. It should work fine even with 5mpx images.

  5. 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.

  6. 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:

  7. 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.

  8. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.