OutOfMemory Exception with Bitmap
<p>i had a problem with load images as bitmap , therefore i use the method: </p>

<pre><code>"decodeSampledBitmapFromFile"
</code></pre>

<p>(the implementation is included)</p>

<p>and i also saved all the bitmaps on the SdCard and every time that i need the Bitmap i load it from the Path which it's stored with the parameters:</p>

<pre><code>decodeSampledBitmapFromFile(path,150,100);



Bitmap image_profile =decodeSampledBitmapFromFile(path,150,100);
</code></pre>

<p>and set the image Bitmap into the imageView that i need (every time that i need a image i load it from the sdCard.</p>

<p>however i still get an OutOfMemoryException after load about 20 images.</p>

<p>So, what is the solution for the OutOfMemoryException?</p>

<p>why even after load small number of images (about 20) i get an OutOfMemoryException?</p>

<p>what is the secret of application like facebook, instagram or youtube that they suceesseed</p>

<p>to load huge number of images without Exception?</p>

<p>i tried everything however i still get Exception.</p>

<p>anyOne has further suggestions what can i implement in order to avoid this exception?</p>

<p>thanks alot</p>

<pre><code>public static Bitmap decodeSampledBitmapFromFile(String path, int reqWidth, int reqHeight) 
    { // BEST QUALITY MATCH

        // First decode with inJustDecodeBounds=true to check dimensions
        final BitmapFactory.Options options = new BitmapFactory.Options();
        options.inJustDecodeBounds = true;
        BitmapFactory.decodeFile(path, options);

        // Calculate inSampleSize
            // Raw height and width of image
            final int height = options.outHeight;
            final int width = options.outWidth;
            options.inPreferredConfig = Bitmap.Config.RGB_565;
            int inSampleSize = 1;

            if (height &gt; reqHeight) {
                inSampleSize = Math.round((float)height / (float)reqHeight);
            }

            int expectedWidth = width / inSampleSize;

            if (expectedWidth &gt; reqWidth) {
                //if(Math.round((float)width / (float)reqWidth) &gt; inSampleSize) // If bigger SampSize..
                inSampleSize = Math.round((float)width / (float)reqWidth);
            }
        options.inSampleSize = inSampleSize;

        // Decode bitmap with inSampleSize set
        options.inJustDecodeBounds = false;

        return BitmapFactory.decodeFile(path, options);
      }
</code></pre>
