Out Of Memory Error After Using App For More Than 5-10 Mins
I've been getting following out of memory issue due to layout inflater when i use my app for little longer than 7-8 minutes. I have checked through many questions in stackoverflow
Solution 1:
the problem is with your view holder. ViewHolder pattern is used to optimise the memory taken by the list. it will create View objects only for the visible part, but in your case every time you are creating a ViewHolder, so whenever you scroll the number of objects will increase and it will cause OutOfMemoryException, the only way to correct is, you need to have some changes in you code. please refer this url. also see the example
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolderItem viewHolder;
// The convertView argument is essentially a "ScrapView" as described is Lucas post
// http://lucasr.org/2012/04/05/performance-tips-for-androids-listview/
// It will have a non-null value when ListView is asking you recycle the row layout.
// So, when convertView is not null, you should simply update its contents instead of inflating a new row layout.
if(convertView==null){
// inflate the layout
LayoutInflater inflater = ((Activity) mContext).getLayoutInflater();
convertView = inflater.inflate(layoutResourceId, parent, false);
// well set up the ViewHolder
viewHolder = new ViewHolderItem();
viewHolder.textViewItem = (TextView) convertView.findViewById(R.id.textViewItem);
// store the holder with the view.
convertView.setTag(viewHolder);
}else{
// we've just avoided calling findViewById() on resource everytime
// just use the viewHolder
viewHolder = (ViewHolderItem) convertView.getTag();
}
....................
.............
}
Post a Comment for "Out Of Memory Error After Using App For More Than 5-10 Mins"