Can't reproduce OOM on AVD device with identical Memory Class - android

Trying to recreate OOM happening on a Samsung S4 (5.0.1) on an AVD (5.0). Both report MemoryClass 128, but I cannot reproduce the OOM condition on my AVD.
I ended up with a really extreme test bitmap of 6000x4000 (96MB with no inSampling. Sure, not a good idea for production, but this is for testing only) I'm using plain BitmapFactory.
The S4 consistently crashes while loading, not a surprise :)
The weird thing: on the AVD this consistently loads without any problem. I'm always able to allocate huge memory nearly to the limits of available MemoryClass, as if there's not fragmentation at all.
Shouln't devices with identical VM heap size behave similar? There should be no major differences in heap fragementation on both devices, as the App has been freshly installed and started.
I'm quite confused, because it looks like an AVD is not a useful device for testing, at least in terms of memory management in ART.
I might have some basic misunderstanding on MemoryClass and VM Heap size. Any ideas?

Related

After how much memory consumption Android throws OutOfMemoryException

Its an old post, but still in most of the places i found out that an android app gets around 16-32 MB memory
But when i check android Profiler, it says that my app is currently using around 350 MB memory on Samsung Galaxy S7.
I get OutOfMemoryException on my app a couple of times, I was curious why its happening. When i dig down a little i found out about 16-32 MB limit, but in actual my app is using 350 MB
I want to know how much memory a normal android phone gives to each app, or is it a variable number, and if no app is running android will not give outOfMemoryException, and if so many apps are in stack then there is a higher chance of OutOfMemoryException
But again there will be some limits.
Android devices vary significantly now that the OS is getting older. You should definitely aim for under 32mb limit if you want your app to work on lower end devices to be safe. Unless you are loading some very large images it sounds like your code is leaking memory.
Start by removing any image (or other asset) loading from your app to see if you still have problems.
If you do, check out LeakCanary, and when you find the leaks learn about them and why they are happening because it will help you immeasurably to become a better Android programmer. One of the chief ways apps leak memory is by passing an Activity context to a long running task :)

High memory usage on application start in Android

I'm making a basic android application, but it is suffering from a LOT of garbage collection (the GC kicks in 4-5 times every second). I tried looking for the root cause and realized that my app has almost no memory as soon as the onCreate function is called.
As soon as the app starts, the DDMS shows almost 91% of the heap being used, mostly by 1-byte arrays. I also ran the memory analysis tool to see if I was leaking memory or something, and even after executing the app, it shows that most of the memory is used up by android.content.res.resources.
Why is my application losing so much memory to resources? The ONLY resource that my app has is a small JPEG image of 22KB. I read elsewhere that sometimes the free heap is misreported because of shared resources etc, but then the GC shouldn't kick in as often as it does when the app is running. Can someone help?
FWIW, the very same app run on a Galaxy S3 shows about 20% heap usage at the start, even though it shows the same amount of total memory (~10 MB). The problematic phone is a Galaxy S2.
Upgraded the phone to Cyanogenmod 10.1, and now the heap usage is ~30% at the start and the GC doesn't kick in anymore. Maybe a bug in the Samsung firmware?

Why does an empty Android ICS app almost occupy all the heap size?

I am developing a game application under Android built for SDKs >= 8. I always tested it under an Android 2.2 phone and never had a problem. When I moved to a Nexus phone with ICS mounted on I started having problems with the heap memory allocation. I tried to remove everything in the app to see where I was having memory leak problems or strange allocations (using both DDMS and MAT under Eclipse) until I decided to just start an empty activity and to do nothing more.
Under Android 2.2 the heap size at startup is about 2.0MB, while under Android 4.1 is about 11MB. Why is there such a great difference?
More, when I play my app the heap size on ICS, the garbage collector quickly starts freeing memory and the whole application becomes slow and with a very low FPS. Under Android 2.2 everything is really smooth and clean, without any single problem.
Does anyone can suggest me where's the difference between these two systems? I don't want to talk about my app implementation (I already spent 2 weeks optimizing code, memory allocation and retention and everything else. Can't do much more), but I want to understand where all that memory goes just at app startup. Also, ICS seems to require much more memory to load and retain bitmaps and drawables.
Okay, I may be late to the party, but I figured out the root of your (and my) problem.
Before Android 3.0 (not sure if this was in the entire 1.x/2.x series) all bitmap related memory was not stored on the heap. So with 3.0 they started locating everything on the heap. I am not sure why an empty application takes up 11MB, I can only guess it is related to the default Android bitmaps used in applications.
Now there is another problem: in earlier versions of Android, there was only a 'drawable' folder, not a 'drawable-hdpi', 'drawable-mdpi' etc... folder. For some reason, when loading in a image from the 'drawable' folder, it takes up HUGE amounts of space. The solution is to add different resolution variants of your images to all the drawable-Xdpi (where X is l,m,h or xh) folders. It reduced my starting heap size from around 26MB to a good 16MB. Even if you don't resize them, and just copy-paste them into the folders, it will still result in quite a significant change in Bitmap sizes.
I hope I help some people by posting this.
-Z

OutOfMemory on both device and emulator

I am getting OutOfMemory Exception while running my project on both emulator and device(acer tablet and samsung galaxy) showing
the application launcher process com.android.launcher has stopped unexpectedly.
I've increase the virtual machine size of emulator to 256mb still there was no change in that exception. How can I avoid this exception? And how can I increase the process size of the heap for both emulator and device?
Please refer to this question
I don't know what kind of application you are running, but it's possible that you have a memory leak in your application. Then it would not matter how big you set your virtual machine size.
Check out the video below on how to find memory leaks in your own application. Works on devices and emulators. (I found a very big memory leak last week, that I didn't know I had in the application)
http://www.youtube.com/watch?v=_CruQY55HOk&feature=player_embedded
Unless you're doing something extreme and actually need lots of memory, you shouldn't have to resort to increasing the memory footprint. The bug that's causing this will probably run over any additional memory you give it.
Take a closer look at what comes before the out-of-memory error. I recently saw that one because I caused an endless configuration change loop. The only thing that stopped that endless loop was running out of memory.
While the few lines above the error looked fine, I realized that the number of log entries was much higher than normal, because it ran through the initialization for my activity repeatedly.
Your issue may be different, but I'm fairly sure that increasing the heap size won't fix it.

Android: performance increase of the app after 15s-120s. Why?

I have a bit of a problem with a game I am working on. The game runs very well on most devices, except Samsung Tab and Galaxy S (it could be more, but I have reports about those two).
What happens on those devices is that the app appear extremely sluggish for 15s-120s then speeds up dramatically (from 5fs to 30fps, which is the normal performance elsewhere). This seems to happen only when the game is installed (or reinstalled).
What could cause that problem?
On the first run, we create a couple of files on the SD card to store settings, but I doubt that could have a lasting effect?
The JIT takes a whiles to kick in? But it runs perfectly fine on other platform with and without the JIT. Admitedly, by disabling the JIT, it appears that the slowdown will last longer on the Tab, so there may be an effect.
Could it be that the device tries to rearrange out the objects are laid out in memory? The game does take quite a bit of space in memory.
Is there any known problem with Samsung devices? (It appears to be a problem on those only)
Any help is welcome.
You could try to call dalvik.system.VMRuntime.getRuntime().setMinimumHeapSize() early in your app with about the size of the heap while your game runs. This will allocate the target heap size at once and avoid reallocs.
I know it is deprecated but who cares if it helps.

Categories

Resources