How Android deals with high cpu and memory usage - android

If the memory or CPU usage of an android device is unusually high,will android take any kind of actions in that case? Like killing apps, reboot etc? Is there an in-built service in android that continuously monitors the CPU and memory usage and take necessary actions in case of any abnormal behavior? If available, at what threshold values of memory and cpu usage will it take action? I did perform a thorough google search but couldn't find any answers. I am talking about inbuilt feature of android and not any third party apps.

I quote this from a good article on android processes
Android does a good job of automatically managing these processes, which is why you don’t need a task killer on Android.
When Android needs more system resources, it will start killing the least important processes first. Android will start to kill empty and background processes to free up memory if you’re running low. If you need more memory — for example, if you’re playing a particularly demanding game on a device without much RAM, Android will then start to kill service processes, so your streaming music and file downloads may stop.
In most cases, Android does this all without you needing to worry about it. Android intelligently uses your device’s RAM for caching apps and other data, because there’s no point in leaving your RAM empty.
You should also read the official documentation on memory management by android operating system.
I think this should clear your doubts. Feel free to ask if you have more...

Related

How to utilize more than 512MB of RAM in your android app?

I am working on an app that will be exclusively used on a limited set of devices, all of which have 6GB of RAM. Currently my app is misbehaving as it touches the 512MB mark. I want to be able to utilize more RAM (~1GB) because I know the devices allocated to users are for one purpose only and that is to use this app so it is not an issue that this app is taking majority of the device RAM.(Google play services are not available in this device and there is no browser either)
The app is doing a wide variety of heavy operations simultaneously while also continuously updating UI so it is bound to cross the 512MB. I have so far managed to keep it all under 480MB but with the plan of upcoming features that I have start implementing today, I think it is inevitable that the app will have to use more RAM.
Please advise on how to utilize more RAM. I have not been able to find any good answer to this
I have tried setting android:largeHeap="true" but that doesn't seem to do to the trick.
Also checked out this relevant post about this but it hasn't provided the best solution in my opinion.
Please advise on how to utilize more RAM
You could:
Split your app into multiple processes. Each process' VM can use up to the heap limit. You will be limited to using inter-process communication (IPC) between the two processes, such as bound services.
Move some of your heavy-RAM logic to C/C++. Native memory allocations (malloc() and things built atop it) are not subject to the heap limit of the VM.
Focus more on optimizing your memory use, such that you can fit within your heap limit.
I know the devices allocated to users are for one purpose only and that is to use this app so it is not an issue that this app is taking majority of the device RAM
If this device has custom firmware, you could raise the heap limit in the firmware.

Android: Clean Master App gives message "your application restarted 9 times in 5 minutes()"

I am getting a message like "your application restarted 9 times in 5 minutes()", when I tried to clean Junk Files using "Clean Master" application.
Please find the screenshot for this issue. I am not able to figure out why this message is coming. Any idea on this???
These apps may have once been useful but the Android has progressed far enough that they are now outdated, unnecessary and rather harmful.
On Windows, you want to keep as much RAM as possible as you can so that programs have enough room to operate. When RAM fills up, Windows is forced to start using hard drive space as virtual RAM and hard drives are much slower than physical RAM.
This is not true for Android.
Android’s operating system has its own native handler for assigning RAM to apps and making sure that all of it is being used in the most optimal way. In fact, Android purposely tries to keep apps loaded into RAM for better performance. RAM is fast, remember? On mobile devices, every bit of speed is critical for a good user experience, so keeping apps in RAM is actually a good thing.
Not only does Android handle RAM assignment, but it also keeps track of background apps so they don’t use up unnecessary processor resources. There’s no noticeable performance hit for leaving apps loaded in RAM.
App killers, memory boosters, performance enhancers, etc all claim wiping memory will speed up the phone. With current versions of Android, that's simply not true. It's actually the opposite. What will happen is the task killer app kills other apps which use resources to process. Then the OS restarts those, or other apps to fill the memory again, which takes even more resources. The task killer app kills again and the process repeats over and over. So in reality, those kinds of apps reduce performance and increase battery usage by restarting apps again and again. Remember, those dormant apps don't consume any additional battery or CPU in the first place.

android ram free up/ garbage collection

All,
I would like to free up ram on my android for a data intensive operation and also be able to free up ram when the user wants to. The first thing I thought of doing was running system.gc(). However, that is not a guarantee that the garbage collector will work. Any suggestions on how to immediately and guarantee that ram is freed up when the code is called.? Also, how do the apps that free up ram when you click a widget accomplish this task?
I guess a better way to phrase this is: How do I manually free up memory like the Android OS?
Thx
You don't have to do this. Android will kill lower priorized apps to free memory if you need more than currently available.
My understanding is that the theory on Android is that running applications should relinquish memory through a callback mechanism when another process with higher priority (i.e., the current foreground process) needs more memory; additionally, the OS will start killing other applications if memory demands increase further.
Therefore, if you want your application to be able to use substantially all of the system's memory, you just need to make sure it stays in the foreground or use some other mechanism to ensure that its memory demands are higher priority than other memory demands (unfortunately, I couldn't say what that latter part would look like exactly).
There's not really much you can or should do manually to free up memory outside of your specific application. The OS is doing the right thing: as memory is needed, it tells applications "delete all non-essential data" and then after that if more memory is needed it tells them to get lost. Any manual approach to freeing up memory would basically do the same thing.
Edit: It sounds like you are wondering what other "memory-freeing" applications are doing. The answer is, they're taking the manual approach and doing the same thing the OS does -- sending signals to running processes. The reason this is unnecessary is that free ram doesn't actually do you any good before you need it. The OS will do this right before you need the extra space, which ensures no processes are killed before absolutely necessary.
Android has a garbage collector. iOS does not.

Android app memory integrity

When an app gets put in the background and the app takes up too much memory. Is it possible for the operating system to corrupt the memory so that when the app is launched again unexpected behavior might ensue? Or will it completely kill the app when it needs the memory so that when I relaunch I'm in a clean state?
The short answer is no.
For more detail on how Android manages memory and how it affects applications, services, etc, see http://mobworld.wordpress.com/2010/07/05/memory-management-in-android/ and http://android-developers.blogspot.com/2010/04/multitasking-android-way.html

How to keep service running after force-stop?

I've seen that if you kill some process, it restarts immediately and keep running. How this implemented? How to inform system that my service should not be killed and if that happened - restart it.
Android just does it. As an OS, Android is specifically designed to run with ram full at all times. So if you kill, or an app force closes it will, if their is room in ram for it be restarted by Android to fill the ram back up.
It does this because even the "fastest" phones are snails to even the most average of desktops and keeping as many programs that you use loaded in ram as possible enables it to simply "resume" the program instead of having to go through the slooooow, time wasting process of having to reload it back into ram and then running it from the beginning.
Android kernels have their own task manager. This means that it will be more efficient than any app-based task manager as it is run at the kernel level, and it should be left up to that task killer to decide when to free up memory or not free up memory. Let Android do what it was designed to do. Anything you do to try and force it to rerun a program or stop a program will, in the long run, slow it down more and possibly even cause stability issues.
However the short answer to your question is that there is no way to tell the "system" that your process should not be killed or to restart when it is closed. That is a choice made entirely by the kernel level task manager.
BTW, why would you want to? I ask this because I don't think you have thought this through very well. Remember, unlike IOS owners who are used to and expect total control over their device to be in the hands of Apple(for good or ill) Android owners expect, and will have control over their device. If you try to take that away from them, you will likely find most people uninstalling your service. And demanding their money back if you charge a fee for it.
I hope this has helped.
Not sure this is something that's good, but I've seen malware processes that have "buddy" processes that revive each other when one or more go down.
I hope whatever you're doing is ethical :-)

Categories

Resources