Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android heap size limit, do we still really need to design applications with a 16 MB limit in mind?

Like the title says, should I still be designing my application around a 16 MB heap size limit? The reason I ask is that I've been developing a game recently that runs fine on my nearly 2 year old Droid 2. But when I test my app using an AVD with a 16 MB heap size limit, I get out of memory errors. Monitoring my application with DDMS shows that the total memory allocated for my game is around 20 MB. It isn't a huge difference, but getting my game to work under that 16 MB limit would really hurt the visuals.

Now, if this was 2008, I wouldn't even be asking this question. But it's 2012, nearly 4 years after the G1 debuted. Is it safe to say that most phones made in the past year allow applications to allocate more than 16 MB of memory? Or am I really screwing myself by not designing my application with a 16 MB limit in mind?

like image 356
phil917 Avatar asked Jan 20 '12 10:01

phil917


People also ask

What is Android heap size?

Most devices running Android 2.3 or later will return this size as 24MB or higher but is limited to 36 MB (depending on the specific device configuration). If your app hits this heap limit and tries to allocate more memory, it will receive an OutOfMemoryError and will terminate. Heap memory is used to allocate objects.


2 Answers

The heap limit varies depending on the device resolution (and probably also other factors). So on a high resolution device the heap limit may be 30MB while on a low resolution G1 it is 16MB. Generally you should change your graphics accordingly so low resolution devices uses low resolution graphics (which takes up less space) and high resolution devices uses high resolution graphics (which takes up more space).

like image 186
Mark Gjøl Avatar answered Nov 15 '22 09:11

Mark Gjøl


Yes we still need it but not in every case. If you are using native code then memory allocated by c compiler does not include in this limit.So you can provide more memory to your application essential component. and second way is to using Texture to draw images using OpenGL.then memory for these Texture does not include from limited memory.

But these technique can not be implement in every case

One more important thing , you can not use these 30 MB completely also.Only 30 % of it is usable for one application .

like image 21
Tofeeq Ahmad Avatar answered Nov 15 '22 08:11

Tofeeq Ahmad