1

I have big issues in tracing down 'bitmap size exceeds VM budget' error. I looked at other questions, and tried all sugesstions (deallocating resources, using bitmap.recycle() and setting variables, bitmaps, canvases to null when activity is destroyed or views are detached from window https://stackoverflow.com/a/6779448/571143, also tried to get rid of 'this' context and used this.getAplicationContext()).

The problem I'm expieriencing is not with a bitmap being too big to load. Everything loads ok at first, but after many repeated changes of current activity I get this error (on device it happens after much more activity changes than on emulator).

So, back to my question, is there a way to use the allocation tracker or heap analyzer to guide me in the right direction? There is no trace of "bitmap allocation" in those tools, only small (mostly less then 1kb) allocations. I've already read this: http://android-developers.blogspot.com/2009/02/track-memory-allocations.html

I know that I'm doing something wrong, because the bitmaps don't deallocate, but the project I'm working on is pretty big, made by a bunch of people, so analyzing everything by hand would be last resort and also extremely time consuming.

I'd appreciate any hints regarding those tools in such scenario.

cheers, kajman

Community
  • 1
  • 1
kajman
  • 1,066
  • 11
  • 24

1 Answers1

1

As you've figured out its some sort of memory leak. If you haven't already, make sure you aren't just accumulating bitmaps in a cache without ever clearing it. Other likely (and more subtle) issues include having a long running task(s) that have references to activities or contexts, or activities registering listeners with long running tasks or singletons.

You can use the Eclipse Memory Analyzer http://www.eclipse.org/mat/ tool to track down which types of references are being held. Its a little tricky on 2.x phones because bitmaps are allocated in native memory and won't show up in your VM heap dump. You will still see the bitmaps, but they won't be listed at the size they actually take up. You can get around this by trying to compare the # of bitmap objects when you first open the app vs after starting lots of new activities.

For an excellent talk on debugging these issues and using the relavent tools, see the google IO talk: http://www.youtube.com/watch?feature=player_embedded&v=_CruQY55HOk

Sam Judd
  • 7,317
  • 1
  • 38
  • 38
  • When I tried to analize hprof dump I got the following exception in the analyzer (I've downloaded the newest version): "Error opening heap dump 'dump.hprof'. Check the error log for further details. Error opening heap dump 'dump.hprof'. Check the error log for further details. Unknown HPROF Version (JAVA PROFILE 1.0.3) (java.io.IOException) Unknown HPROF Version (JAVA PROFILE 1.0.3)" – kajman Mar 27 '12 at 15:35
  • Ok, I've found this: http://stackoverflow.com/questions/6219049/error-openning-hprof-file solution – kajman Mar 27 '12 at 15:37
  • yeah its hprof-conv filename.hprof targetname.hprof where hprof-conv is a tool in the sdk. – Sam Judd Mar 27 '12 at 16:18