1.大量查询数据库时cursor没有关闭

错误写法:

Cursor cursor = getContentResolver().query( );

if(cursor != null)

{

cursor.moveTOFirst();

while(!cursor.isAfterLast())

{

..............

}

}

正确写法:

Cursor cursor = getContentResolver().query( );

if(cursor != null)

{

cursor.moveTOFirst();

while(!cursor.isAfterLast())

{

..............

}

cursor.close;

cursor = null;

}

2. Bitmap对象没有及时回收

因为Bitmap对象比较占内存,所以,Bitmap对象用完之后,最好使用Bitmap.recyle() 来回收Bitmap对象所占的内存。

3. 在Adapter中没有使用缓存中的convertView

错误写法:

pubic View getView(int position, View convertView, ViewGroup parent)

{

LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

View view = inflater.inflate(R.layout.listview_item_manage_bookshelves,null);

........................

}

正确写法:

pubic View getView(int position, View convertView, ViewGroup parent)

{

View view;

if(convertView == null)

{

LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

view = inflater.inflate(R.layout.listview_item_manage_bookshelves,null);

}

else

view = convertView;

........................

}

4. 根据Activity的生命周期,回收资源

在OnStop() 或者 onDestroy()方法中,对一些方法,对象回收,例如:

if(mArraryList != null)

mArrayList = null;

......................

.......................

System.gc();
System.gc();

更多相关文章

  1. android如何查看app的内存占用情况
  2. Android内存控制
  3. Android 工具类的两种写法---单例模式与静态方法
  4. Android GreenDao 建表及 获取SessionDao对象 单例
  5. android加载文件的方式,路径的写法
  6. Android 内存泄漏——context泄漏
  7. Handler 内部类导致的内存泄露修改方法
  8. 【Android】广播的写法
  9. 更改系统给APP应用分配最大的内存空间

随机推荐

  1. android网络访问兼容
  2. android Activity 半透明效果
  3. Android打开第三方地图使用方法
  4. Android(安卓)双击返回键退出程序
  5. Android(安卓)控件 —— ListView
  6. Android简单文件浏览器源代码
  7. android 广播传参数
  8. Android(安卓)实现滑动的六种方式
  9. android之获取信息终端
  10. Android(安卓)日期时间选择控件