OutOfMemory Exception Occurs in Android App
<p>I have a problem that I am receiving data from JSON response, there are many images in data also. There are large amount of data as more than 100. Therefore it returns OutOfmemory exception when I try to load it in LazyAdapter or when try to call method as NotifydatasetChanged of LazyAdapter. Please suggest any solution regarding the same.</p>

<p><strong>Code:</strong></p>

<pre><code>final ProgressDialog dialog = ProgressDialog.show(
                    ResearchList.this, "Research List       ",
                    "Please wait...   ", true);

            final Handler handler = new Handler() {

                public void handleMessage(Message msg) {

                    // System.out.println("The id after Save:"+id.get(0).toString());

                    // catagory.addAll(keyword_vector1);
                    linear_Category_Child.setVisibility(View.GONE);
                    linear_Category_Child_Child.setVisibility(View.VISIBLE);
                    //tv_Child_Header.setText("Volvo");
                    tv_CategoryChildHeader.setText(from);
                    setHeaderImage(tv_CategoryChildHeader.getText().toString());

                    if(coll.getDisplayNames().size()!=0)
                    {
                        adapter = new CategoryListLazyAdapter(
                                ResearchList.this);
                        lvCategory.setAdapter(adapter);
                        Utility util = new Utility();
                        util.setListViewHeightBasedOnChildren(lvCategory);

                    }
                    else
                    {
                        /*lvCategory.invalidate();
                        lvCategory.setAdapter(null);*/
                        AlertDialog.Builder builder = new Builder(ResearchList.this);
                        builder.setTitle("Attention!");
                        builder.setMessage("No Data Available for the Particular Search.");
                        builder.setPositiveButton("OK",
                                new DialogInterface.OnClickListener() {

                                    @Override
                                    public void onClick(DialogInterface dialog, int which) {
                                        // TODO Auto-generated method stub

                                    }
                                });

                        builder.create().show();
                    }
                    /*Utility util = new Utility();
                    util.setListViewHeightBasedOnChildren(lvCategory);*/
                    dialog.dismiss();
                }
            };

            final Thread checkUpdate = new Thread() {

                public void run() {
                    try {
                        String sortEncode = URLEncoder.encode("mpg");
                        String filterEncode = URLEncoder.encode(filter);
                        String clientEncode = URLEncoder.encode("10030812");
                        String fromEncode = URLEncoder.encode(from);
                        String toEncode = URLEncoder.encode(to);
                        String catUrl = "/v1/vehicles/get-make-models.json?sort="
                                + sortEncode
                                + "&amp;filter="
                                + filterEncode
                                + "&amp;client-id="
                                + clientEncode
                                + "&amp;from="
                                + fromEncode;
                        genSig = new GetSignature(catUrl, "acura");
                        try {
                            signature = genSig.getUrlFromString();
                        } catch (InvalidKeyException e1) {
                            // TODO Auto-generated catch block
                            e1.printStackTrace();
                        } catch (NoSuchAlgorithmException e1) {
                            // TODO Auto-generated catch block
                            e1.printStackTrace();
                        }
                        // jsonString =
                        // getJsonSring("http://api.highgearmedia.com/v1/vehicles/get-models.json?make=acura&amp;client-id=10030812&amp;signature=LWQbdAlJVxlXZ1VO2mfqAA==");
                        // String signatureEncode =
                        // URLEncoder.encode(signature);
                        String urlEncode = URLEncoder.encode(catUrl
                                + "&amp;signature=" + signature);
                        jsonString = getJsonSring("http://apibeta.highgearmedia.com"
                                + catUrl + "&amp;signature=" + signature);
                        System.out.println("The json category:===&gt;"
                                + jsonString);
                    } catch (ClientProtocolException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    } catch (URISyntaxException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    JsonParse json = new JsonParse(jsonString);
                    json.parseCat();
                    LIST_SIZE = coll.getDisplayNames().size();
                    for (int i = 0; i &lt;= BATCH_SIZE; i++) {
                        // countriesSub.add(COUNTRIES[i]);
                        countriesSubCat.add(coll.getDisplayNames().get(i));
                        imagesSubCat.add(coll.getImages().get(i));
                        YearSubCat1.add(coll.getYears().get(i));
                        YearSubCat2.add(coll.getYears().get(i + 1));
                        mpgSubCat1.add(coll.getMpg().get(i));
                        mpgSubCat2.add(coll.getMpg().get(i + 1));
                        priceSubCat1.add(coll.getPrice().get(i));
                        priceSubCat2.add(coll.getPrice().get(i + 1));
                        ratingSubCat1.add(coll.getRating().get(i));
                        ratingSubCat2.add(coll.getRating().get(i + 1));
                    }
                    setLastOffset(BATCH_SIZE);
                    handler.sendEmptyMessage(0);

                }

            };
            checkUpdate.start();
</code></pre>

<p><strong>GetJSonString Method(Error Place):</strong></p>

<pre><code>public String getJsonSring(String api_url) throws URISyntaxException,
            ClientProtocolException, IOException {
        try {
            HttpClient client = new DefaultHttpClient();
            HttpGet request = new HttpGet();
            URL url = new URL(api_url);
            URI uri = new URI(url.getProtocol(), url.getHost(), url.getPath(),
                    url.getQuery(), null);
            request.setURI(uri);

            HttpResponse response = client.execute(request);
            InputStream ips = response.getEntity().getContent();
            BufferedReader buf = new BufferedReader(new InputStreamReader(ips, "UTF-8"));




            StringBuilder sb = new StringBuilder();
            String s;
            while (true) {
                s = buf.readLine();
                if (s == null || s.length() == 0)
                    break;
                sb.append(s);

            }
            buf.close();
            ips.close();
            return sb.toString();

        }

        finally {
            // any cleanup code...
        }

    }
</code></pre>
