title: OutOfMemory Error in ArrayList. Android
body: <p>I am working on http get request on android.</p>
  
  <p>I receive a huge amount of json data from server, a string is unable to handle or store that data and getting OutOfMemory Exception.</p>
  
  <p>Then I tried to save it in arrayList which can store a maximum of Integer.Maximum value.
   but it is getting OutOfMemory exception while storing at ~8970 location.</p>
  
  <p>Here is my link which has json data.</p>
  
  <p><a href="http://ec2-50-19-105-251.compute-1.amazonaws.com/ad/Upload/getitemlist10122013035042.txt" rel="nofollow">http://ec2-50-19-105-251.compute-1.amazonaws.com/ad/Upload/getitemlist10122013035042.txt</a></p>
  
  <p>here is my code:</p>
  
  <pre><code>ArrayList&lt;String&gt; newarr = new ArrayList&lt;String&gt;();
      try {
  
          URL url = new URL(urlFilePath);
          HttpURLConnection urlConnection = (HttpURLConnection) url
                  .openConnection();
  
          urlConnection.setRequestMethod("GET");
          // urlConnection.setDoOutput(true);
  
          // connect
          urlConnection.connect();
  
          // Stream used for reading the data from the internet
          InputStream inputStream = urlConnection.getInputStream();
  
          // create a buffer...
          byte[] buffer = new byte[1024];
          int bufferLength = 0;
          int check;
          while ((bufferLength = inputStream.read(buffer)) &gt; 0) {
              String decoded = new String(buffer, 0, bufferLength);
              newarr.add(decoded);    // OutOfMemory Exception.   
          }
  
          fileOutput.close();
          buffer = null;
          inputStream.close();
          String path = file.getAbsolutePath();
          return path;
      } catch (final MalformedURLException e) {
          e.printStackTrace();
          return "";
      } catch (final IOException e) {
          e.printStackTrace();
          return "";
      } catch (final Exception e) {
          System.out.println("EXCEPTION:: " + e.getMessage());
          e.printStackTrace();
          return "";
      }
  </code></pre>