0

Some times my app crashes in emulator saying the heap memory is too low. What this heap means? My app uses local data base and ksoap services. The heap problem is not occuring every time. What is thereason behind it?

Piotr Chojnacki
  • 6,837
  • 5
  • 34
  • 65
Jashan PJ
  • 4,177
  • 4
  • 27
  • 41

5 Answers5

5

Heap is the amount of space your app is allotted in the Dalvik Virtual Machine in the RAM for storing data.

You get an exception when you try to load so much stuff that it exceeds the heap space given to you.

You can get around it by loading only what you need, and downsizing images when you load them so that you don't load a higher size than is required for display.

Raghav Sood
  • 81,899
  • 22
  • 187
  • 195
5

The heap is what the memory manager uses to keep track of the memory. It consists of one or more unused memory areas, and all blocks of used memory.

When the heap gets too low, it means that there is not enough free memory as the application is trying to use more memory than there is available. There can be several specific reasons for this, for example:

  • Your application is using too much memory.

  • Other applications are using much memory, leaving less for your application.

  • Your application is allocating large blocks of memory, but the free memory is fragmented into smaller blocks so it can't be used.

Try to reduce the memory usage, and make sure that you release memory properly that you are not using any more.

Guffa
  • 687,336
  • 108
  • 737
  • 1,005
  • 2
    It should be noted on Android that your heap space is usually not shrunk because other applications are using more space. In most cases, apps will be killed of in order of decreasing priority so that the running apps have the minimum amount of heap space (minimum of 16 MB, usually more. Varies per device). – Raghav Sood Apr 19 '13 at 12:07
2

In programming, an area of memory reserved for data that is created at runtime -- that is, when the program actually executes. In contrast, the stack is an area of memory used for data whose size can be determined when the program is compiled.

Chirag
  • 56,621
  • 29
  • 151
  • 198
1

All object's static varaibles are stored on heap. Each application will be allocated some amount of heap space by the dalvik virtual machine. When the heap size grows and your application needs memory garbage collector kicks in to free memory. When garbage collection takes places, the app is paused. Larger the heap size more frequent garbage collection which increases the pause time.

Local variables are stored on the stack.

The garbage collection works by mark and sweep. It uses a mark and sweep algorithm to free memory space.'

You can use a MAT Analyzer to find the cause of memory leaks.

Check the link below the talk is about memory management

http://www.youtube.com/watch?v=_CruQY55HOk

Edit:

A bit more to how the algorithm works

http://www.brpreiss.com/books/opus5/html/page424.html

Technical details of Android Garbage Collector

Community
  • 1
  • 1
Raghunandan
  • 132,755
  • 26
  • 225
  • 256
0

The heap (in Java) stores dynamically allocated variables, such as objects.when the heap is running low on memory, the JVM will run garbage collection.

Garbage collection uses processing cycles, which will slow down your phone.

In case you're wondering, the other place in memory where things are stored is called the stack, which stores arguments and parameters.

For More Information Visit this SO answer.

Community
  • 1
  • 1
Hardik Joshi
  • 9,477
  • 12
  • 61
  • 113