0

Here is the story: I run my app from Eclipse and let say it uses 20 MB of RAM in Task manager.
Then I close my app using "Back button".
I check in Task manager and processes that my app is closed.
Now I run my app again from phone but now it will use 32 MB.
I close my app and run it again from phone and it will use 45 MB of RAM and this will continue for every restart.

It will add ~ 12 MB on every start.
If I run my app from Eclipse it will reset back to 20 MB.

I'm using MyApp to store some non static data and a SQLiteDatabase:

public class MyApp extends Application {

}

I can see that even If I close my app with back btn my apllication will remain in active processes.

vovahost
  • 34,185
  • 17
  • 113
  • 116

2 Answers2

3

You should use the Eclipse Memory Analyzer Tool (MAT) - this is obviously a memory leak. You need to acquire a heap dump from DDMS, convert it with the hprof-conv tool in the sdk and load it into MAT.

Check this blog post on the official Android devs blog.

npace
  • 4,218
  • 1
  • 25
  • 35
1

Try calling android.os.Process.killProcess(android.os.Process.myPid()); on your main activity's onDestroy method.

Orkun Kocyigit
  • 1,137
  • 10
  • 21
  • It works but can you please tell the reason why this is working. – vovahost Jul 26 '13 at 11:55
  • 1
    Android keeps some data/instructions about your application in order to start it fast if it opened again within close interval,with that command you are making sure that instructions and extra data won't be saved. – Orkun Kocyigit Jul 26 '13 at 12:00
  • 2
    This should be considered a last resort! The real problem is a memory leak, and it should be fixed. The only times I have needed to use this are for custom layout engines that have either static contexts or native openGL views. – Phil Jul 26 '13 at 12:03
  • 1
    Yes Phil is right, this is quick and dirty solution and it shouldn't be used in big projects as it may lead into process or data corruption when next time you start the application. – Orkun Kocyigit Jul 26 '13 at 12:05