Skip to main content

Vincent Tsao's Library tagged "memory leak"   View Popular, Search in Google

Apr
24
2010

  • As part of my job, I ran into memory leaks issues in Android applications and they are most of the time due to the same mistake: keeping a long-lived reference to a  Context.
  • There are two easy ways to avoid context-related memory leaks. The most  obvious one is to avoid escaping the context outside of its own scope. The  example above showed the case of a static reference but inner classes and  their implicit reference to the outer class can be equally dangerous. The  second solution is to use the Application context. This  context will live as long as your application is alive and does not depend  on the activities life cycle. If you plan on keeping long-lived objects  that need a context, remember the application object. You can obtain it  easily by calling  Context.getApplicationContext()  or Activity.getApplication().
  • 1 more annotation(s)...
1 - 5 of 5
Showing 20 items per page

Diigo is about better ways to research, share and collaborate on information. Learn more »

Join Diigo
Move to top