There are a lot of tutorials,articles on the web about memory perfomance, and how to improve it,remove leaks etc..
But I haven't found information how many memory apps should use. Of course less is better,but I haven't found information about what is maximal memory which app can use and works well on the most of devices.
Is ok for app to use around 50-60 MB of RAM?
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.
Sometimes we encounter the memory issues,such as the OOM problems.And We inevitably have to manage the memory.Android has set a limit to the memory used bye each app.The maximum limit probably is the 32Min the early versions of android,such as 1.5,1.6,2.1.
Android of v4.0 has exceeded this limit.We can set android:largeHeap to "true" in the AndroidManifest,so the app could increase the memory limit.
I'm develeping the wallpaper app.The app can show many pictures in high definition.But the memory used by the app always reach the limit of more than 60M in the android of 720p, about 100M in the android of 1080p.
The overuse of memory is unacceptable for me.And I'm looking for the means to resolve it all the time.
My friends,How much memory your app will take up when you develop your app during debugging or running?Is there a memory-manage mechanism in the code?Look forward to your reply.
The amount of memory used by bitmaps is based on what's in the bitmap, not the size of the file. There's a few things you can do to reduce the footprint of the bitmap being loaded in to memory, which, in turn will reduce the amount of memory your app is using.
There's a great talk here from Google I/O for memory management that will help and another that will help you check to see if you have any memory leaks as well.
Also, note that if you use Bitmap.Config.RGB_565 you can half the amount of memory that the Bitmap is using (each pixel value is stored in 2 bytes instead of 4)
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 9 years ago.
Improve this question
By design, Android apps are very limited in the amount of heap memory they can use. The limitation for SDK apps is as little as 16MB on old devices. This design choice usually makes sense because the OS tries to support multi-tasking on devices which are usually very low on memory - so each task gets its own small ration.
The memory limitation varies per device. On stock Samsung Galaxy S2 for example, each app gets somewhere between 32MB-64MB. This device has 1GB of RAM, so a single task can only use about 5% of what the device can offer.
It's worth to mention that memory strategy on iOS is very different. To the best of my knowledge, there is no externally enforced limit on how much memory an iOS app can use. You can allocate as much as you want until the system runs out of memory. If you're too greedy, other background apps will be terminated.
Let's get this out of the way - this isn't a discussion about which memory strategy is better.
The memory limitation on Android is hard to swallow for certain types of apps. Graphic-intensive apps (such as games) need lots of memory to hold bitmaps. Even a web browser should be pretty hard to implement under the default limit.
When resource optimization isn't enough, the standard strategy for overcoming the memory limit is using the NDK. The "native" heap in Android doesn't have artificial limitations and behaves much like the heap on iOS. Using the "native" heap to hold bitmaps works well - this is actually how bitmaps were kept on Android 2.3.3 and lower (the JVM still limited them artificially though).
I'm looking for an NDK+JNI library to hold unlimited bitmaps in the "native" heap. Its Java interface should be identical to the stock bitmap API. I'm not aware of any public project for this purpose and will appreciate your help to find one. If you've implemented this before and willing to share your code, it will be appreciated as well.
Final comment: Please do not make this a discussion about the morality of having such a library available to the general public.
The heap limit on recent 2GB devices is around 192MB. Apps that need a large amount of memory, such as image editors, can include android:largeHeap=true in the app manifest to increase that to a higher limit (currently around 512MB).
Working around the limits is generally a bad idea. It's calibrated on each device based on the amount of physical memory, the display size, and how the device performs when it has a bunch of apps running. Remember that, on Android, your app isn't the only thing present, and not all of physical memory is reserved exclusively for apps (a big piece goes to the kernel, buffers for multiple frames of graphics and video content, and so on).
The bigger your app is, the more likely it is to be killed. The kernel tries very hard to not kill the foreground app, which means you're going to start squeezing out background processes -- or cause them to do so much paging and restarting that it starts to impact the performance of your game.
Having said all that, I think you're looking for this.
As my app is using a lof of pictures, I get the famous issue of OutOfMemoryError on older devices.
Explanations: http://androidactivity.wordpress.com/2011/09/24/solution-for-outofmemoryerror-bitmap-size-exceeds-vm-budget/
According to Android Developers your device has at least 16MB of heap
space (T-Mobile G1) for storing your application data. But as Yekmer
said in Yekmer’s Posterous , images are not stored in the heap space.
The space reserved for images in an Android application is very
small, and having a big application using a lot of images, may easily
lead to the OutOfMemoryError.
My question
Having a lot of code, I would like to know if there is a tool in Android Studio that would help me to track the memory used by images and to know which steps of my code are increasinf the most the memory used.
What I don't need
I know how to get information like ActivityManager.getMemoryInfo() or Runtime.getRuntime().totalMemory() but I guess they won't be usefull, right?
Some ideas
I tried to understand the numbers given by "adb shell dumpsys meminfo", but I don't know if that would be a great start...
Use MAT to diagnose memory leaks and other out-of-memory causes:
Android Developers Blog post
Google I|O conference video
I've spent the last few days trying to remove memory leaks in my game, resulting in many out of memory errors. I'm on the verge of adding a significant amount of graphics, that while not hugely complicated, will add significantly to the processing requirements of my system, and I'm a bit worried about my memory usage, and I was hoping someone might have some tips for me. I don't want to go below Android 2.1, so please tailor any answers to that end.
First of all, my game consists of:
2 activities, 13 XML files (Some relating to a small part of a layout, some dialogs, and 2 directly related to activities.
A number of drawables, made in Adobe Illustrator and converted to PNG. These are probably large, but not unusually large, and for the most part, only small amounts of them are in memory at any given time.
Quite a few dialogs.
Targeted towards Android 1.6 and above.
I used the newest Admob, and as a result, I have to build against 3.2.
My default heap size for my emulators is around 24 MB.
A few sample images from my game:
What I have learned:
Despite my total app size being only around 500K, I somehow am taking up 24 Megs, as calculated by adb shell procrank.
I have done considerable optimization, but am not seeing large increases in memory.
Using tools to find what is in the Heap typically only show around 7 MB avaliable, with around 3 MB being used. Sometimes, when opening new dialogs and the like, I see an increase, but I can't say that I see it being all that large...
MAT shows that none of my classes are using an unusually large amount of memory.
So, given all of this, my questions.
Is 24 Mb an actual requirement to develop to (1.6+ android)?
Assuming it is, how can I both allow for nicer graphics for systems which can handle it, but not crash and burn for older systems?
What are some common gotchas that I can use to improve my memory usage?
Without seeing your actual code, I can't say if the following will be relevant to you or not. However, it is worth a shot.
If you are not already doing so, you can consider using something called an LruCache. http://developer.android.com/reference/android/util/LruCache.html
Using this tool, you can determine at what point your cached objects (such as Bitmaps) will become eligible for garbage collection. So, if you want to set it at 4mb (for example) the OS will deal with it should it try to grow beyond it. (See docs for implementation details and a good example).
The only downside is that that little gem only came along with 3.2, so you would have to make that your min SDK in the AndroidManifest, or do a check programatically at run time for the api level to determine if you can use it. Pre 3.2 I would say you need to call recycle() on any Bitmaps you are using, but if you have optimized already I would think the chances are good you are already doing this.
This is a nice little snippet about the difference between the heap and native memory. http://code-gotcha.blogspot.com/2011/09/android-bitmap-heap.html It may (depending on what you are doing) help you to understand why you are not seeing the drop in memory you are expecting.
And finally this post from SO should help when dealing with heap size as well:
Detect application heap size in Android
Hope that helps.