2

I have a custom listview where each list item has 5 entries and these entries come from SQLite database. There are such 8 list-items in this listview. My code for custom adapter is:

public class VaccinListAdapter extends BaseAdapter
    {

        private Context context;
        private List<VaccinInfoPOJO> vaccinInfo;


        public VaccinListAdapter(Context c,List<VaccinInfoPOJO> list)
        {
            context=c;
            vaccinInfo=list;
        }
        @Override
        public int getCount() {
            return vaccinInfo.size();
        }

        @Override
        public Object getItem(int pos) {
            return vaccinInfo.get(pos);
        }

        @Override
        public long getItemId(int i) {
            return i;
        }


        @Override
        public View getView(int position, View convertView, ViewGroup viewGroup) {

            ViewHolder holder;

            VaccinInfoPOJO entry=vaccinInfo.get(position);
            if (convertView == null) {
                LayoutInflater inflater = (LayoutInflater) context
                        .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                convertView = inflater.inflate(R.layout.vaccin_list_style, null);
                holder=new ViewHolder();
                holder.diseasevalue=(TextView)convertView.findViewById(R.id.vaccin_lv_disease);
                holder.animals=(TextView)convertView.findViewById(R.id.vaccin_lv_animalnames);
                holder.vaccinname= (TextView)convertView.findViewById(R.id.vaccin_lv_vaccinname);
                holder.dosevalue=(TextView)convertView.findViewById(R.id.vaccin_lv_dosagevalue);
                holder.timevalue= (TextView)convertView.findViewById(R.id.vaccin_lv_timevalue);
                convertView.setTag(holder);
            }
             else {
                holder = (ViewHolder) convertView.getTag();
            }

            holder.diseasevalue.setText(entry.getDisease());

            holder.animals.setText(entry.getAnimal());


            holder.vaccinname.setText(entry.getVaccine());


            holder.dosevalue.setText(entry.getDose());


            holder.timevalue.setText(entry.getTime());

            return convertView;
        }

    }

And I am using this ViewHolder class as suggested here:

 static class ViewHolder
    {
           TextView diseasevalue,animals,vaccinname,dosevalue,timevalue;

    }

I am getting Out of memory exception after a long stream of this grow heap sequence::

04-18 09:42:46.033: DEBUG/dalvikvm(370): GC_CONCURRENT freed 45K, 21% free 10597K/13255K, external 1055K/1567K, paused 10ms+10ms
04-18 09:42:48.154: INFO/dalvikvm-heap(370): Clamp target GC heap from 17.901MB to 16.000MB
04-18 09:42:48.154: DEBUG/dalvikvm(370): GC_CONCURRENT freed 68K, 18% free 12622K/15303K, external 1055K/1567K, paused 10ms+11ms
04-18 09:42:48.673: INFO/dalvikvm-heap(370): Clamp target GC heap from 18.030MB to 16.000MB
04-18 09:42:48.673: DEBUG/dalvikvm(370): GC_CONCURRENT freed <1K, 18% free 12754K/15367K, external 1055K/1567K, paused 11ms+12ms
04-18 09:42:48.893: INFO/dalvikvm-heap(370): Clamp target GC heap from 18.030MB to 16.000MB
04-18 09:42:48.893: DEBUG/dalvikvm(370): GC_FOR_MALLOC freed 0K, 18% free 12754K/15367K, external 1055K/1567K, paused 219ms
04-18 09:42:48.893: INFO/dalvikvm-heap(370): Clamp target GC heap from 16.030MB to 16.000MB
04-18 09:42:48.893: INFO/dalvikvm-heap(370): Grow heap (frag case) to 16.000MB for 24-byte allocation
04-18 09:42:49.194: INFO/dalvikvm-heap(370): Clamp target GC heap from 18.030MB to 16.000MB
04-18 09:42:49.194: DEBUG/dalvikvm(370): GC_FOR_MALLOC freed 0K, 18% free 12754K/15367K, external 1055K/1567K, paused 219ms
04-18 09:42:49.204: INFO/dalvikvm-heap(370): Forcing collection of SoftReferences for 24-byte allocation
04-18 09:42:49.414: INFO/dalvikvm-heap(370): Clamp target GC heap from 18.015MB to 16.000MB
04-18 09:42:49.414: DEBUG/dalvikvm(370): GC_FOR_MALLOC freed 14K, 18% free 12740K/15367K, external 1055K/1567K, paused 212ms
04-18 09:42:49.414: INFO/dalvikvm-heap(370): Clamp target GC heap from 16.015MB to 16.000MB
04-18 09:42:49.794: INFO/dalvikvm-heap(370): Clamp target GC heap from 18.015MB to 16.000MB
04-18 09:42:49.794: DEBUG/dalvikvm(370): GC_CONCURRENT freed 0K, 18% free 12740K/15367K, external 1055K/1567K, paused 6ms+6ms
04-18 09:42:50.014: INFO/dalvikvm-heap(370): Clamp target GC heap from 18.015MB to 16.000MB
04-18 09:42:50.014: DEBUG/dalvikvm(370): GC_FOR_MALLOC freed 0K, 18% free 12740K/15367K, external 1055K/1567K, paused 214ms
04-18 09:42:50.014: INFO/dalvikvm-heap(370): Clamp target GC heap from 16.016MB to 16.000MB
04-18 09:42:50.014: INFO/dalvikvm-heap(370): Grow heap (frag case) to 16.000MB for 60-byte allocation
04-18 09:42:50.314: INFO/dalvikvm-heap(370): Clamp target GC heap from 18.016MB to 16.000MB
04-18 09:42:50.314: DEBUG/dalvikvm(370): GC_FOR_MALLOC freed 0K, 18% free 12740K/15367K, external 1055K/1567K, paused 223ms
04-18 09:42:50.324: INFO/dalvikvm-heap(370): Clamp target GC heap from 16.016MB to 16.000MB
04-18 09:42:50.324: INFO/dalvikvm-heap(370): Grow heap (frag case) to 16.000MB for 8-byte allocation
04-18 09:42:50.724: INFO/dalvikvm-heap(370): Clamp target GC heap from 18.016MB to 16.000MB
04-18 09:42:50.724: DEBUG/dalvikvm(370): GC_CONCURRENT freed 0K, 18% free 12740K/15367K, external 1055K/1567K, paused 16ms+5ms
04-18 09:42:50.994: INFO/dalvikvm-heap(370): Clamp target GC heap from 18.015MB to 16.000MB
04-18 09:42:50.994: DEBUG/dalvikvm(370): GC_FOR_MALLOC freed <1K, 18% free 12740K/15367K, external 1055K/1567K, paused 247ms
04-18 09:42:51.004: INFO/dalvikvm-heap(370): Clamp target GC heap from 16.016MB to 16.000MB
04-18 09:42:51.004: INFO/dalvikvm-heap(370): Grow heap (frag case) to 16.000MB for 24-byte allocation
04-18 09:42:51.304: INFO/dalvikvm-heap(370): Clamp target GC heap from 18.016MB to 16.000MB
04-18 09:42:51.304: DEBUG/dalvikvm(370): GC_FOR_MALLOC freed 0K, 18% free 12740K/15367K, external 1055K/1567K, paused 226ms
04-18 09:42:51.314: INFO/dalvikvm-heap(370): Clamp target GC heap from 16.016MB to 16.000MB
04-18 09:42:51.314: INFO/dalvikvm-heap(370): Grow heap (frag case) to 16.000MB for 24-byte allocation
04-18 09:42:51.724: INFO/dalvikvm-heap(370): Clamp target GC heap from 18.016MB to 16.000MB
04-18 09:42:51.724: DEBUG/dalvikvm(370): GC_CONCURRENT freed 0K, 18% free 12740K/15367K, external 1055K/1567K, paused 20ms+6ms
04-18 09:42:51.934: INFO/dalvikvm-heap(370): Clamp target GC heap from 18.016MB to 16.000MB
04-18 09:42:51.934: DEBUG/dalvikvm(370): GC_FOR_MALLOC freed 0K, 18% free 12740K/15367K, external 1055K/1567K, paused 207ms
04-18 09:42:51.934: INFO/dalvikvm-heap(370): Clamp target GC heap from 16.016MB to 16.000MB
04-18 09:42:51.934: INFO/dalvikvm-heap(370): Grow heap (frag case) to 16.000MB for 8-byte allocation

Where to go now? Any help would be appreciable.

EDIT::

I had made a huge silly mistake. When I was running a loop to fill the Arraylist with data the loop was like:

for(cursor.moveToFirst();!cursor.isAfterLast();cursor.moveToFirst())

here the last moveToFirst was getting this loop into infinite state. I changed it to moveToNext. Whoa...God bless me.!!!

4

0 回答 0