2

I've got an application that allocates and releases a lot of memory (mostly bitmaps). I'm very careful about releasing memory, etc, and the application never crashes for out of memory reasons. For any 2.x OS, Debug.getNativeHeapAllocatedSize() always returns something that makes sense. However, running the same app on 3.x, Debug.getNativeHeapAllocatedSize() keeps on increasing. In fact, on the XOOM, if I run the app long enough, the returned value goes way beyond the device heap (which is 256 MB). I was able to get it up to 350 MB before I stopped testing. At the same time, running the Eclipse Memory Analyzer, it shows no problem with memory whatsoever. Everything seems to be released as expected.

Now, I tend to believe the memory analyser, but what is going on with getNativeHeapAllocatedSize()? Is it just plain wrong, or do I not understand what it's giving me for Honeycomb? If it's wrong, then how can I find the amount of memory I'm using at runtime?

Thanks!

haimg
  • 4,547
  • 35
  • 47
user982687
  • 325
  • 6
  • 14
  • I think GC simply doesn't kick in on 3.x as soon as it does in earlier Android versions. I'll mark this question as a possible duplicate of this question: http://stackoverflow.com/questions/5060307/bytebuffer-not-releasing-memory – haimg Oct 06 '11 at 18:04
  • I don't think that's the issue. If the GC did not run, then the Eclipse Memory Analyser would show the same high values, would it not? But it doesn't. It shows what I expect. – user982687 Oct 06 '11 at 18:07
  • Are you running with hardware acceleration turned on? Are you using a WebView? WebView will use a lot of memory with hardware acceleration turned on. – Romain Guy Oct 06 '11 at 18:22
  • Yes, hardware acceleration is turned on, but it's not a webview. It's a regular view (derived from LinearLayout) with bitmaps drawn into it using the Canvas, e.g. canvas.DrawBitmap... – user982687 Oct 06 '11 at 18:26
  • Do you have a simple app that reproduces what you are seeing? I would like to run it myself and see exactly what's going on. – Romain Guy Oct 06 '11 at 18:30
  • I appreciate that very much, but no, I'm afraid I don't, but I can think about what it would take to create one. Perhaps I can do more looking here by disabling certain areas of the code and seeing what happens. I'm fairly certain I don't have any dangling references anywhere or this would not work on 2.x. – user982687 Oct 06 '11 at 18:47
  • Looks like I'm not seeing the problem with HW acceleration turned off. – user982687 Oct 06 '11 at 19:17
  • From more testing, it's looking like calls to canvas.getMatrix and canvas.setMatrix are allocating memory that's never released. I'm not certain about this, but it's looking that way. These calls are used several times in my view's OnDraw method, which runs continuously, hence the memory loss. I'm not explicitly allocating any memory myself. – user982687 Oct 07 '11 at 05:43

0 Answers0