2013年7月24日 星期三

Android Refactor Items

Avoid Memory Leak

  1. Change string concatenation to  StringBuffer.append()
  2. Try using the context-application instead of a context-activity
  3. Shorten session timeout call HttpSession.invalidate(). when app exit()
  4. Avoid non-static inner classes in an activity if you don't control their life cycle, use a static inner class and make a weak reference to the activity inside. The solution to this issue is to use a static inner class with a WeakReference to the outer class, as done in ViewRoot and its W inner class for instance (Not sure how to do it. I know "using strong references for parent-to-child references, and weak references for child-to-parent references, thus avoiding cycles". It'll need to trace the code like View<->Context kind of stuff)
  5. Watch later http://stackoverflow.com/questions/1147172/what-android-tools-and-methods-work-best-to-find-memory-resource-leaks
  6. Watch later http://www.curious-creature.org/
  7. LBNL : http://developer.android.com/tools/debugging/ddms.html

References

http://android-developers.blogspot.co.uk/2009/01/avoiding-memory-leaks.html
http://www.mindfiresolutions.com/How-to-avoid-Memory-leak-issue-in-Java-1001.php
http://en.wikipedia.org/wiki/Weak_reference
http://www.ibm.com/developerworks/java/library/j-leaks/

沒有留言:

張貼留言