Android OutOfMemoryError:?

前端 未结 8 1504
孤街浪徒
孤街浪徒 2020-11-28 06:02

I am sporadically getting an OutOfMemoryError: (Heap Size=49187KB, Allocated=41957KB) in one of my apps. What can I do to diagnose this?

  01-09         


        
8条回答
  •  庸人自扰
    2020-11-28 06:55

    This could occur for several reasons, you might be keeping references to other parts of your code too long. You might be loading to large bitmaps which together with holding on to many references gives you OOM, etc.

    Normally when an OOM occurs a hprof (snapshot of the Heap) is created on the root of the sdcard (or internal storage if sdcard does not exist), which can be read by tools like Eclipse MAT (included in the android tools if you use Eclipse). First one might need to convert the hprof with hprof-conv tool. Here's one tutorial of how to use Eclipse MAT: Investigating Your RAM Usage. The leak suspects report is a good first read when hprof is loaded in Eclipse MAT

    After profiling you you could read up on how to load images effectively from Displaying Bitmaps Efficiently

    There's also several popular image loading libraries such as universal image loader and picasso available, that do what you need with ease.

提交回复
热议问题