推荐安卓开发神器(里面有各种UI特效和android代码库实例)
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();
5. 自定义的adapter等,当使用完后应该及时释放资源,将值置为null.如
adapter = null;
listview.setAdapter(null);
相关推荐
如果不能使用,请修改根目录下的project.property的android:target为你当前有的target(不知道怎么改的同学可以从8到21一个个数字去试哦) 程序实现点击屏幕后聚焦拍照功能,并把图片存入sd卡camera目录下。但打开时无...
uniapp项目体量过大时,打包H5会报错, - process out of memory 解决放案: 替换HBuildX内置\HBuilderX\plugins\node\node.exe版本 添加\HBuilderX\plugins\compile-node-sass\node_modules\node-sass-china\...
内存溢出 (OOM)是指程序在申请内存时,没有足够的内存空间供其使用,出现out of memory;比如只申请了一个integer,但给它存了long才能存下的数,那就会出现内存溢出。 内存泄露 (memory leak)是指程序在申请内存...
内存溢出(Out Of Memory):Android系统中每一个应用程序可以向系统申请一定的内存,当申请的内存不够用的时候,就产生了内存溢出。 内存泄漏:当某个对象不再被使用,即不再有变量引用它时,该对象占用的内存就会...
如果不小心,你的Android应用很容易浪费掉未释放的内存,最终导致内存用光的错误抛出(out-of-memory,OOM)。 一般内存泄漏(traditional memory leak)的原因是:当该对象的所有引用都已经释放了,对象仍未被释放。...
关于android内存机制的介绍,以及bitmap的内存泄露等问题的处理方式
漏金丝雀 :baby_chick: Android的内存泄漏检测库。执照Copyright 2015 Square, Inc.Licensed under the Apache License, Version 2.0 (the "License");you may not use this file except in compliance with the ...
如果不小心,你的Android应用很容易浪费掉未释放的内存,最终导致内存用光的错误抛出(out-of-memory,OOM)。一般内存泄漏(traditionalmemoryleak)的原因是:当该对象的所有引用都已经释放了,对象仍未被释放。(译者...
但是尽管有了垃圾回收机制,在开发android的时候仍然时不时的遇到out of memory的问题,这个时候我们不禁要问,垃圾回收机器去哪儿了? 我们主要讲的是handler引起的泄漏,并给出三种解决办法,其中最后一种方法...
Android的虚拟机是基于寄存器的Dalvik,它的最大堆大小一般是16M,有的机器为24M。...如果我们的内存占用超过了一定的水平就会出现OutOfMemory的错误。 掌握OOM异常的处理,并可以对应用进行相应的优化