I would like to know if the video memory (VRAM) that an android OpenGL application can use is limited ? If so, would you know what the limit is?
The limit depends on how much the device has. On many devices, the VRAM is actually part of the general purpose RAM. I don't think there is a way to find how much there is at runtime. The total RAM on current devices will vary between about 256 MB and up. However, you may have problems allocating more than a certain limit (16MB, 24MB, 28MB etc.) that is fixed per device. See VM Limit in Android 2.0 for details.
The OpenGL driver allocates normal RAM until you run out of it and normal RAM size is device independent.
Related
I recently created an android application, and after I completely redid my spinner dropdown menus using a custom adapter, some devices are crashing. It's very minimal, like 3 people have experienced crashes ever, but still it's something I want to address if possible because the apps minimum SDK version is as low as 16, so I imagine it's older devices that struggle the most. Attached is a pic of the crash report! This specific device has 2 GB of memory, you would think that would easily be enough to load a spinner with a bunch of low quality images right?
Thanks for the help in advance! This is the crash report: https://i.imgur.com/Wtm5pX9.jpg
The amount of memory the device has != the amount of memory you can use. The OS takes a lot. Other apps take a good amount. And even the memory you can use is fragmented into different pools. Generally "OutOfMemoryException" means out of Java heap memory (out of native memory would be a different crash, for example). Bitmap memory goes into different buckets on different OS versions, they've changed it a few times. So it could be a variety of reasons- you have too large an image that's using insane memory, your have leaks, you have sufficient memory on the device but the heap allocation spiked for some reason, your network layer isn't efficient (if you use Volley to download images its particularly stupid about that). There's not enough info here to actually give you a suggestion. I'd try to replicate it on a simulator with the RAM purposely capped at 1GB or smaller and see if you can reproduce it.
I was reading about OutOfMemory error in Android, which comes when Android runs out of memory. Do we know that if my app consumes some x MB of memory then it will give OutOfMemory error? Does Android allocates a specific amount of memory to each app depending on the device and total physical memory?
For example, I've a device with 2GB RAM installed, 500MB is taken by OS, 500 MB is taken by other apps. Now my app has 1048MB of memory to run. So in this particular case when the system gives OutOfMemory?
Each app has some memory limit it can utilize for heap allocations. It differs for different phones (and you can increase it in manifest as well). This answer provides a great detail on this, giving specific figures for some models and settings.
As for how it is determined:
it tends to be based more on screen resolution, as higher-resolution screens tend to want to manipulate larger bitmaps, so Google makes heap size recommendations that, hopefully, device manufacturers will abide by.
CommonsWare
What you are looking for is best described by google itself Here
To get how much memory you can use you could do this:
ActivityManager manager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
int memoryClass = manager.getMemoryClass();
Log.v("onCreate", "memoryClass:" + Integer.toString(memoryClass));
your OutOfMemory Exception caused by Heap size , not about the RAM .
To maintain a functional multi-tasking environment, Android sets a
hard limit on the heap size for each app. The exact heap size limit
varies between devices based on how much RAM the device has available
overall. If your app has reached the heap capacity and tries to
allocate more memory, it will receive an OutOfMemoryError.
here an useful link : https://developer.android.com/training/articles/memory.html
hope that help you :)
I'm developing an android app that has a lot of bitmaps that uses a lot of RAM. My question is that when I keep my app running for a long time and the ram usage exceeds 64 MB, the app crashes with an "OUT OF MEMORY ERROR, VM won't let us allocate ... etc".
While other apps such as facebook reaches 200 MB ram sometimes without any crashes and with a very fast performance. My device is Galaxy S II.
and please notice that my question is not about reducing the memory usage, it's about the difference in memory limit between my app and other apps.
Thanks.
I think there is a limit on the amount of memory that an application can use... Used to be 32MB... There might be a permission that you can change to request more memory, in the same way that you can request hardware acceleration. From a quick google android:largeHeap="true" might be your answer... Also Runtime.getRuntime().maxMemory(); might help? This link was also interesting...
The amount of memory that the vm is reserving for each application is not part of the Android ecosystem and can't be determined, it's part of the configuration given by the manufacturer.
Usually the last word about the memory size for each vm is given by the file build.prop.
Do not use the NDK trick if you do not know what are you doing.
My relatively small application for Android with nice graphics that consists mostly of 9patch drawables consumes about 10MB of the memory.
Do you think that it is OK? Or I should optimize it somehow? What is acceptable memory consumption for small applications?
To get approximate per-application memory limit for any device you can use Activity member function
public int getMemoryClass ()
There is a 16/24MB memory limit for application running in android. This thread gives you more info..
This tutorial talks about some good memory management practices..
There is no rule that small app should not take more than x mb memory. The default value of memory allocated by the Dalvik VM for each application is of 16 MB, using the Android 1.6 OS and higher. As long as your app is using memory under this limit, its perfectly fine.
If you really want to optmize your code, always make sure, you don't have any memory leaks in your app, and you are clearing your resources after use. That would only be the trick. :)
10MB has been fine in my experience. The smallest Max Heap Size you are likely to come across is 16MB, and a lot of devices have higher than that now.
I'm not sure why the drawables are taking up so much ram though. Maybe try using a zipaligned APK if you are not already. The export signed APK wizard in eclipse is an easy way of getting one - the development builds are not generally zipaligned.
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?
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).
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 .