0

I create a custom dialog with imageview.

When it close and open oftentimes this error occur

java.lang.OutOfMemoryError: Failed to allocate a 35236108 byte allocation with 16775584 free bytes and 16MB until OOM

dialog code:

msg.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            final Dialog dialog = new Dialog(Settings.maincontext);
            dialog.setContentView(R.layout.perfil);
            dialog.show();
            Vibrator vibration = (Vibrator) Settings.maincontext.getSystemService(Context.VIBRATOR_SERVICE);
            vibration.vibrate(100);
            dialog.setCanceledOnTouchOutside(true);
            return false;
        }
    });

I believe that at the end of the dialog i need to clear the memory so there is space to the next dialog.

3 Answers3

0

The OutOfMemory Occure in your case because your Image size is very big. try to Reduce the Image size and set it. or you have to set android:largeHeap="true"in Manifest.xml file.

Harshad Pansuriya
  • 20,189
  • 8
  • 67
  • 95
0

This error may be because you are trying to load in to memory the images without freeing them. This may help you: https://developer.android.com/training/displaying-bitmaps/load-bitmap.html

The link explain you how to load images in an eficient way or load scaled versions of the same in order to reduce the memory used.

tknbr
  • 139
  • 1
  • 13
0

This happens becouse you are showing an imageview containg a very big picture. My solution is to use something like Picasso to optimize the pictures that you want to display.

It is very simple:

   Picasso.with(context) 
    .load(url) 
    .resize(50, 50) 
    .centerCrop() 
    .into(imageView) 

In this way you will not run out of memory.