Is leaked memory and all the memory resources being freed once application termintates?

StackOverflow https://stackoverflow.com/questions/20949896

  •  24-09-2022
  •  | 
  •  

Question

Once android application terminates (closed either by user or by OS), is leaked memory and all other memory resources being freed? Or we need to do it manually? What will be the best way to track and handle memory issues in android?

Was it helpful?

Solution

a memory leak in a situation where some objects are not used by the application any more, but GC fails to recognize them as unused.

GC is automatically done periodically by the JVM.

An android application can only be terminated by the OS. (safely at least)

if the app is closed by the user, it still runs in the background, once the os decides that it needs to close the application, either to free up some memory or the application stack is full, it will terminate the application and the memory will be freed.

If the application is terminated, all resources used by the application is freed.

99.9% of the time you do not need to call garbage collection on android. The OS takes care of itself. Would probably cause more harm to manually call GC

There are some cases where memory is leaked, but there are workarounds to dispose things in these cases.

OTHER TIPS

If process terminates then Yes, but that does not happen very often. Android is designed to keep processes in background to start them quickly once user want to go back to you app.

You should not rely that your app will be terminated to fix some memory leaks. There are tools to fix them, like dumping HPROF file and using memory analyzer, also using weak references, and using good programming practicies - mostly not leaking activities.

[edit] - there are resources that are not always freed on process end, while working with android TTS apis, I found that after few app crashes I have to reset device to be able to use svox voices.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top