Is possible to re allocate the heap memory in Android - android

I am developing an application in that I am getting the Out of memory Exception this is happened due to the insufficient memory. Is possible re allocate the memory once reach the maximum allocate memory.

It is not possible to allocate more memory than is in budget which system gives you.
You can try to put android:largeHeap to your manifest, but it works only on some devices and it isnt generally best solution.
Instead you should find out where you are using all that memory and try to optimize to cut it down.
On modern devices there should be plenty of memory and should be enough for most operations with good design. System places gap on memory usage to prevent poorly designed apps, from depleting memory pool.

Related

how much memory usage is reasonable for a typical android application

I'm sorry for asking this duplicate question. But as you can see in that link the topic is saying one thing but the content is about something else.
I'm not asking how to manage or how to monitor the memory, just want to know how much memory usage you call a memory friendly app. And from what range you consider as using too much memory.
Thank you
Short Answer: As low as possible.
Long Answer: To allow multiple running processes, Android sets a hard limit on the heap size alloted 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, the system throws an OutOfMemoryError, and to avoid running out of memory, you can to query the system to determine how much heap space you have available on the current device.
You can query the system for this figure by calling getMemoryInfo(), which provides information about the device's current memory status, including available memory, total memory, and the memory threshold—the memory level at which the system begins to kill processes.
For more details, see this
https://developer.android.com/topic/performance/memory

Android: why is memory usage for one application drasmatically larger than allowable memory for one process

As I researched, Android allocates limit memory for each process, maybe range from 16MB to 24MB for each one. Here is reference
Nevertheless when I view memory usage for one application in setting, I often see one normal application costs hundred megabytes for memory (on one process). There is a conflict here that I cannot understand.
Thanks :)
NDK code can use more system RAM than can a single Dalvik/ART process. Also, the app might be using more than one process, or it might be using android:largeHeap to request an above-normal heap size.

Does increasing RAM help to prevent OOM?

OOM happens when the heap gets full. But what if we increased the size of the RAM of the device, will that help prevent OOM?
I tried to look at tutorials on how to prevent OOM , which recommended multi-threading and trimming down the size of the bitmap. But I still get OOM errors.
But what if we increased the size of the RAM on the device, will that help prevent OOM?
Yes and no. The answer is "it depends on why you are running out of memory."
If you are trying to manipulate a 2GB Bitmap on a 1GB device, then yes, adding a few extra GB of RAM will solve your problem.
If you have a rogue operation that is constantly allocating new Objects, then adding additional memory will just delay the OOM Exception. Extra RAM is not a long term solution to poor memory management.
You need to work to identify why you are running out of memory first. If the issue is that you really do need more RAM (which is fairly unlikely), then go ahead and add more. If the problem is that you are unnecessarily allocating memory or leaking objects, then fix those problems first.
With Bitmaps specifically, you often don't need the full quality image. If your image is stored at 1080p resolution but the device is only a 480p screen, then loading the entire image into memory is a waste of space since most of the image won't be used anyway.

OutOfMemoryException far from memory limit

In my application I use quite a lot of assets to render. This caused my application to crash with an exception indicating that there is no more memory left (when allocating a byte array). Using meminfo I've seen that my process uses about 40mb of memory which according to my calculations is correct (so no hidden excessive memory allocation in my code).
The total memory usage on my system is 300mb. My tablet however supports 1gb of memory and I wonder why it throws me an exception at a usage of 300mb. Is there some per process limit that I need to change? Or are there any other things I'm missing about androids memory management?
Add this to androidManifest in application tag
android:largeHeap="true"
to make things work but this will consume more memory hence more gc calls

Does Malloc get memory from RAM or cache

I have a Native android app which Makes a lot of calls to Malloc. I am trying to allocate a chunk of the RAM and then run some memory intensive tasks to see how my Android device handles it. But I am not sure if the device is taking memory from the RAM or other sources of memory. Is there a way to find out? If it is taking memory from the cache, how do I make it so I am allocating the memory only from the RAM?
But I am not sure if the device is taking memory from the RAM or other sources of memory
malloc() allocates memory from the process' heap, which in turn comes from the device RAM. It has done so for decades.

Categories

Resources