Android Dialog memory leak on app exit - android

I have noticed that dialogs (not sure about DialogFragments) will report a memory leak when you put in the app in the background and then dismiss it while in the background. Of course the way to handle this is to clean it up in onPause so its not really an issue, but my question is:
What are the impact of memory leaks if they are occurring as the app is exiting? It is talked about here https://developer.android.com/training/articles/memory.html under "Switching Apps"
but the way it is worded leaves me to think maybe it is just referring to apps put in the background, not apps being closed hence the reason it is under Switching Apps.
Any clarification or pointing to additional resources would be greatly appreciated.
Thanks

Related

Why does Android "kills" backgrounds apps? What can you do about it?

I'm only on search for the reason why Android does this and what can you do to "stop" it or handle it when coding any app. I haven't found any info about this except some yt videos that teach you how to stop it when using your Android smartphone. I'm looking for documentation or something like that to read and learn why does this happen and how to handle it.
Sorry for my bad english, not native. Thank you.
Why? Because a device is a computer and therefore the limited resources should be optimized. The optimizations favors the app with the user is interacting, making the user experience fluid.
How this happen and how to handle it is the life cycle
And how to make things even if the app is not open it is about the workmanager
From the official documentation
It is important that application developers understand how different application components (in particular Activity, Service, and BroadcastReceiver) impact the lifetime of the application's process. Not using these components correctly can result in the system killing the application's process while it is doing important work.
and how it happens :
To determine which processes should be killed when low on memory, Android places each process into an "importance hierarchy" based on the components running in them and the state of those components

How to deal with a force close

I am currently developing a game application for Android. My problem is that it sometimes crashes and displays the "Unfortunately...has stopped" dialog. But running the application again does NOT force close the app when getting to the same point, it will just appear every so often.
What are some potential reasons that this might happen? I've done some research but couldn't really find anything
You should review your logcat for possible Exceptions.
If you have no Exceptions causing your app to crash -meaning your code is aparently "ok"- there's the chance the application is consuming lots of memory. If your application is making your Garbage Collector to overwork, Android may shut down your application.
You must take care you are not overcreating objects, or leaving a load behind to be cleaned by the Garbage Collector. This means, if you can reuse objects, that's a good idea.
There's an <application> element in the Android Manifest. You can set there an attribute named android:largeHeap="true". In this way Android will assign more memory for your application. But do do this as a last resort. Try to first improve the object management in your app. This ain't easy task, so good luck.

Should an android app close its service when exit if there's nothing to do

Some apps in my phone(android) leave one or more services after I close them (using back key and clearing recent app), because I can see them in my Settings->Apps->running tab. Some of these apps obviously don't need to have a service running in the background when they're not being opened because they actually don't need to do anything when it's closed, at least no reason I can think of. Can these kind of apps be considered as "bad" app? Or if there's some reason for this since I find it relatively common.
You right
I prepared a presentation on this topic and i found this is worst mistake ever done by developer.
Leaving a service running when it’s not needed is one of the worst
memory-management mistakes an Android app can make. So don’t be greedy
by keeping a service for your app running. Not only will it increase
the risk of your app performing poorly due to RAM constraints, but
users will discover such misbehaving apps and uninstall them.
I found very much about this topic here https://developer.android.com/training/articles/memory.html

How to solve memory leaks , Is useing service a option?

My app is very slow, than ı searched web and find out there are memeory leaks on my app. But the problem is ı have tons of codes and too many activities. There are tons of refenrences and leaks. Its gonna be really hard work if ı do this way. Than I tougth if I transfer all codes to a services (as ı understand the services is not leaking memory) this would be easier for me. I wnant to ask that, if you had this statuation, than how would you try to solve it? I learned about memory managment 4 days ago and 10 hours of day learned about it. But ı dont want to go wrong direction again. And my app live on market and users still waiting for a update. I need to be fast and affactive more than I can be. How would you salve this leaks on fastest way ? Is servis realy a option ?Thanks..
I decided to clear all leaks and make a better codding. This is absolute way. By the way, for more performance, when a activity is hidden clear all data that took. and clear all images. if activity is active again reload all contents again.
also: create a clas and make a static instance of aplication context. then call this where you wrigth .getaplicationcontext(). this thecnic called by weak reference. by this your activities will be garbace collected.
and use this.isfinishing() method at onpost() method of every asyctask.
you can use onstart and onstop calls for this. my apps ram usage was 250 mb and now 70mb.

Memory from activities not released

I've an application that has some foreground activities and also a service that updates some widgets.
The problem is that, as the process remains for the service, the memory from the other activities ,if they are opened, is never reclaimed.
Looking at that response from Roman Guy it seems that can be normal. But it is? For how much time android keeps the resources of not used activities? They can live for hours?
How can I know easily if the activities are leaked or are simple not reclaimed? I've tried with a program from AndroidMarket (FreeMemoryRecover) and it's cleared but I suspect that it kills the process and then restart the service...
Any help or suggestion will be heavily appreciated.
Note 1: I've investigated with a HeapDump + Eclipse MAT and I don't see strange references holding my activities
Note 2: I've already asked some questions about this problem:
Post 1
Post 2
The ability for Android to have multiple Activities, in different states, is a design principle as it allows users to quickly switch between activities without consciously having to shutdown whatever they were doing before. They can then quickly return to a previous activity.
If Android needs to pause an Activity, and quickly unpause it, it's going to need to keep the Activity's resources available to it.
If the memory is part of a terminated Activity, then it's leaked (very unlikely as the Linux kernel will reclaim all memory that was used when the process terminates), else it's either being actively used or is potentially about to be used.
What is that concerns you about this memory?
I would try the following :
Launch your app play with it to be sure it is fully loaded and use as much memory as it can.
Then hit the home button and launch the navigator, open techcrunch.com, lemonde.fr, youtube.com, dailymotion.com, launch a video from youtube, open up and play angry bird and last but not least open up a pdf document.
After that Android will have needed the memory back quite for sure. If your app is still there, you might have a problem, if its not, then everything went smoothly.
By the way, good on you to put so much concern in being a good citizen in AndroidLand !!
See my comment below your question.
See Romain Guy's post about Android memory leaks.
Specifically, look at the comment on the solution in the Launcher app. (look at unbindDrawables code here)
Use Context.getApplicationContext() whenever possible instead of your activity's context.

Categories

Resources