Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2110966
  • 博文数量: 413
  • 博客积分: 10926
  • 博客等级: 上将
  • 技术积分: 3862
  • 用 户 组: 普通用户
  • 注册时间: 2006-01-09 18:14
文章分类

全部博文(413)

文章存档

2015年(5)

2014年(1)

2013年(5)

2012年(6)

2011年(138)

2010年(85)

2009年(42)

2008年(46)

2007年(26)

2006年(59)

分类: LINUX

2010-03-26 18:39:02

  1. Trace Memory Allocation
    http://developer.android.com/resources/articles/track-mem.html
  2. Trace Memory Leak in Native Code
    • http://discuz-android.blogspot.com/
      Key words:
      Automatic Memory Leak Tracking on Android
      android memory usage with hprof
  3. Avoid Memory Leak
    http://developer.android.com/resources/articles/avoiding-memory-leaks.html
  4. Common Memory Leak
    1. Don't release field of Activity
      When activity is closed with calling finish(), the finalize() method may not be called, the instance may stay in memory for re-use in future, but if memory is low, the activity will be released. So don't excpet GC to release field of Activity subclass, you must release them explicitly in onDestroy method. ie.
      public void onDestroy()
      {
          super.onDestroy();
          m_textField = null;
          m_hashTable.clare();
          m_hashTable = null;
      }
    2. Send messages in a wrong way
      Correct:
      Message message = handler.obtainMessage(); //handler is an instance of type Handler
      //Set fields of message
      message.id = xxx
      message.obj = xxx
      ...
      message.sendToTarget();
      Wrong:
      Message message = new Message();
      message.id = xxx
      message.obj = xxx
      ...
      handler.sendMessage(message);
    3. That forget to call close() method may cause memory leak
      • Cursor
      • IO Stream, such as InputStream/FileInputStream, OutputStream/FileOutputStream
      • Socket
      • Database
    4. That forget to call clear() may cause memory leak
      • HashTable
      • Map and its subclass,
      • Collection and its subclass, such as List, ArrayList, LinkedList, Vector, Set, Stack, Queue,
    5. ...
  5. ...
阅读(1891) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~