2

I got problems about grow heap which I have 2 questions to ask.

First, How can I suppose to check current grow heap in my devices?

Second, How can I decrease my grow heap size to prevent out of memory error?

barssala
  • 463
  • 2
  • 6
  • 22

1 Answers1

4

Do you mean you want to check the total size of the heap your application can use? Or how much free memory is left in the heap?

To see the total size of the heap you could call

Runtime rt = Runtime.getRuntime();
long maxMemory = rt.maxMemory();
Log.v("onCreate", "maxMemory:" + Long.toString(maxMemory));

This will tell you how much memory in bytes your app is allowed to use (source)

To find out how much is left you could do the following

When are you getting out of memory errors? A starting point could be to override onLowMemory() method...

Community
  • 1
  • 1
bScutt
  • 872
  • 8
  • 23
  • Example `Grow heap ( frag case ) to 3.373 for 19764-byte allocation`, I want to know this detail – barssala Feb 26 '13 at 12:06
  • 1
    That message means that the heap (memory used) has been expanded to 3.373MB to accommodate a 19764-byte object being loaded into memory. If you edit your question with a code example of where it is crashing I could maybe help more. – bScutt Feb 26 '13 at 12:29