0

I am loading images from webserver using AQuery and getting out of memory exception (java.lang.OutOfMemoryError: thread creation failed) . I did everything that docs suggest while there are OOM. but i am not able to escape out. can you please suggest me why i am getting OOM after loading 40 images ?

5
  • What have you done to avoid OOM and that does not work? Commented May 17, 2016 at 7:48
  • Can you please share your code snippet?? Commented May 17, 2016 at 7:57
  • BitmapAjaxCallback.clearCache(); AQUtility.cleanCacheAsync(mContext, triggerSize, targetSize); aq.id(R.id.image_center) .progress(R.id.progressbar2) .image(urlString, false,false, 200, 0); @ Alexander Kulyakhtin Commented May 17, 2016 at 8:05
  • if you using lower version and the memory is less then also you getting this error Commented May 17, 2016 at 8:08
  • I have tested my app on Samsung S6 Edge Commented May 17, 2016 at 10:07

3 Answers 3

2

The best way to avoid a OOM especially when dealing with images is as follows:

  1. If possible and your api supports, then try to fetch images based on resolution just enough for the viewing on the mobile device.
  2. Using volley or Picasso on its own does not solve the OOM issue.. In order to handle the OOM issue, make use of the BitmapFactory provided by the framework to resize the downloaded image to a size just enough for the view in which it is being displayed. You can do something as follows

    ImageView imgView = findViewById(R.id.img);

    int height = imgView.getHeight();

    int width = imgView.getWidth();

    Bitmap = yourBitmapOfFullResolution;

    Bitmap scaledBitmap = Bitmap.createScaledBitmap (yourBitmapOfFullResolution, height, width, true);

    imgView.setImageBitmap(scaledBitmap);

Sign up to request clarification or add additional context in comments.

1 Comment

I have use the following code for setting an image. AQuery aq; aq.id(R.id.image_left).progress(R.id.progressbar1).image(urlString, true,true, 200, 0);
1

Try Volley Library for this. its much faster and efficient. and i think your problem is the heap size of your device, if you are running and testing your app on emulator. then you can easily increase the heap size by editing the device configuration.

2 Comments

I have tested my app on Samsung S6 Edge.
i had same issue once but i solved it by enlarging heap size. try uninstall the app first then run fresh your app.
1

Thrown when a request for memory is made that can not be satisfied using the available platform resources. Such a request may be made by both the running application or by an internal function of the VM.

Add this feild in application tag of manifest file

 android:largeHeap="true"

1 Comment

use picasso lib square.github.io/picasso and compress images using BitmapCompress during adding image files on server

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.