title: OutOfMemoryError on batch image download
body: <p>I have a large list of objects, all of whom have a path to their image "ex. <a href="http://www.google.com/image.jpg" rel="nofollow">http://www.google.com/image.jpg</a>" and I need to download the image and save the drawable to the object..</p>
  
  <p>I was using AsyncTask, but even if I use my own threads I always end up with 'OutOfMemoryError' at some arbitrary point in the list. The images are never larger than 82Kb (Is this too big for android tablets?) in size, but I think the sheer number of images is causing the process as a whole to fail.</p>
  
  <p>Here is what I'm currently doing.</p>
  
  <pre><code>class DownloadImageTask extends AsyncTask&lt;ArrayList&lt;Item&gt;, Void, Void&gt; {
  
  private static int num =1;
  
  @Override
  
  protected Void doInBackground(ArrayList&lt;Item&gt;... items) {
  
      try {
  
          if(items.length == 0)
  
              return null;
  
          HttpURLConnection connection;
  
          InputStream input;
  
          for(ArrayList&lt;Item&gt; itemlist : items) {
  
              for(Item i : itemlist) {
  
                  Log.d(JusTouchMenu.TAG,"[Item]Image request to url:"+i.getImagePath());
  
                  try {
  
                      connection = (HttpURLConnection)new URL(i.getImagePath()).openConnection();
  
                      connection.setRequestProperty("User-agent","Mozilla/4.0");
  
                      connection.connect();
  
                      input = connection.getInputStream();
  
                      i.setImage(new BitmapDrawable(BitmapFactory.decodeStream(input)));//Requires a drawable
  
                      connection.disconnect();
  
                  } catch(Exception e) {Log.e(JusTouchMenu.TAG,"[Item]Unable to download image @ '"+i.getImagePath()+"'",e);}
  
                  Log.v(JusTouchMenu.TAG, "[Item]Image decoded @ '"+i.getImagePath()+"' #"+num++);
  
                  for(Tag pt : i.tags()) {
  
                      Log.d(JusTouchMenu.TAG,"[Item-&gt;Tag]Image request to url:"+pt.getImagePath());
  
                      try {
  
                          connection = (HttpURLConnection)new URL(pt.getImagePath()).openConnection();
  
                          connection.setRequestProperty("User-agent","Mozilla/4.0");
  
                          connection.connect();
  
                          input = connection.getInputStream();
  
                          pt.setImage(new BitmapDrawable(BitmapFactory.decodeStream(input))); //Requires a drawable
  
                          connection.disconnect();
  
                      } catch(Exception e) {
  
                          Log.e(JusTouchMenu.TAG,"[Item-&gt;Tag]Unable to download image @ '"+i.getImagePath()+"'",e);
  
                      }
  
                      Log.v(JusTouchMenu.TAG, "[Item-&gt;Tag]Image decoded @ '"+pt.getImagePath()+"' #"+num++);
  
                  }
  
              }
  
          }
  
      } catch(Exception e) {
  
          Log.e(JusTouchMenu.TAG,"Error decoding image inside AsyncTask",e);
  
      }
  
      return null;
  
  }
  </code></pre>
  
  <p>Thanks!</p>