Stephan Tual
Stephan Tual

Reputation: 2637

What MUST go inside 'onPause()' (releasing resources)

In short, I'm trying to avoid memory leaks. I have read http://kohlerm.blogspot.co.uk/2009/02/memory-leaks-are-easy-to-find.html and I have identified some, by looking at what kept the GC from releasing the memory.

That said, I'm still not sure what should be ALWAYS manually released by doing things like: - unregistering listeners - nulling references - removing views from layouts

... versus what is automatically released when the system destroys the application.

Upvotes: 1

Views: 490

Answers (1)

Akhil
Akhil

Reputation: 14038

Some things I could point out You need to do when Activity is getting paused :

  1. Making sure you are not using static rferences to the context or the activity or views. Make them null if you are.

  2. Stop the media being played ( if any) and release mediaplayer's resources. They are very limited.

  3. A surfaceholder gets destroyed if an activity is paused, will have to release resources.

  4. Save all the necessary vaiables/state as it is last lifecycle method guaranteed to be called.

  5. Stop animations, timers, asyctasks as per your need.

Upvotes: 4

Related Questions