Pages Navigation Menu

Coding is much easier than you think

What does “heap” mean in Android?

Sometimes when you run your app in emulator, the app may crash saying the heap memory is very low. So this will make you think of a simple question,

  • What this heap means?
  • The heap problem is not occurring every time. What is the reason behind it?

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.

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 based on device).

All object’s static variables 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.’

So, in order to avoid the above problems try to reduce the memory usage, and make sure that you release memory properly that you are not using any more.

PROJECT ENQUIRY  CONTACT US

To keep getting updates on Android, JAVA Design Patterns, STRUTS 2, SPRING MVC, SOAP-UI, SharePoint, FTP, SFTP tutorials and many more please like our facebook fan page SimpleCodeStuffs