1

This is the error I am receiving on the Android log, exactly, this is:

08-06 12:16:28.763: E/dalvikvm-heap(27065): Out of memory on a 184-byte allocation.

The "184" depends, sometimes it is 184, sometimes it is 24, other 42......etc....

I was looking everywhere, and this error is common for Activities where loading pictures, my problem is that I am not loading picture, but only text. My Activity is a ListActivity, where I load data from a DataBase(only text), and after a while, all the time the same error.

Anyone knows how to solve it??

Thanks a lot!

zapotec
  • 2,628
  • 4
  • 31
  • 53

3 Answers3

3

Since you are using a listActivity check if you have implemented the optimizations shown here.

I solved a similar issue with list view by implementing the optimization

Here are some excerpts from the presentation about optimizing a listAdapter

The Slow way

public View getView(int position, View convertView, ViewGroup parent) { 
     View item = mInflater.inflate(R.layout.list_item_icon_text, null);
     ((TextView) item.findViewById(R.id.text)).setText(DATA[position]); 
     ((ImageView) item.findViewById(R.id.icon)).setImageBitmap( 
             (position & 1) == 1 ? mIcon1 : mIcon2);
     return item; 
}

The Proper way

 public View getView(int position, View convertView, ViewGroup parent) { 
     if (convertView == null) { 
         convertView = mInflater.inflate(R.layout.item, parent, false); 
     } 
     ((TextView) convertView.findViewById(R.id.text)).setText(DATA[position]); 
     ((ImageView) convertView.findViewById(R.id.icon)).setImageBitmap( 
             (position & 1) == 1 ? mIcon1 : mIcon2); 
     return convertView; 
 }

The Best Way

static class ViewHolder { 
        TextView text; 
        ImageView icon; 
}

 public View getView(int position, View convertView, ViewGroup parent) { 
         ViewHolder holder; 

         if (convertView == null) { 
             convertView = mInflater.inflate(R.layout.list_item_icon_text, 
                     parent, false);
             holder = new ViewHolder(); 
             holder.text = (TextView) convertView.findViewById(R.id.text); 
             holder.icon = (ImageView) convertView.findViewById(R.id.icon); 

            convertView.setTag(holder); 
        } else { 
            holder = (ViewHolder) convertView.getTag(); 
        } 

        holder.text.setText(DATA[position]); 
        holder.icon.setImageBitmap((position & 1) == 1 ? mIcon1 : mIcon2); 

        return convertView; 
    }
Gautam
  • 7,868
  • 12
  • 64
  • 105
0

Sometimes you can get OutOfMemory error, when you try to execute too long SQL statements (eg, you don't use the String[] argument for the variables in the query, but hard code them in the statement).

Try editing your where statements to field=? format, and specify the variables in the designated query parameter.

See this thread: Sqlite Out of Memory when preparing update statement

If this isn't the problem in your case, than I can't think of anything else with this little information.

Community
  • 1
  • 1
Adam Monos
  • 4,287
  • 1
  • 23
  • 25
  • Thanks, but the problem is not when I make the query, but after I do the query, after moving up and down on the scroll on the list adater, it gets out of memory. I think is that I need to optimize the list adapter, but I don´t know how....... – zapotec Aug 07 '12 at 06:23
0

In my case, the problem caused by big-size images. I removed some of them (temporarily for test) and the problem solved. Note that in my case, the problem just was in lowest API-level I was trying the app (API 16).

Finally, optimized them for solving the problem permanently.

Mir-Ismaili
  • 13,974
  • 8
  • 82
  • 100