Clearing heap memory for memory deletion

I know that the question about lack of memory has already been asked, but I could not find a solution

In the Factory bitmap, I exited the exception memory, even use

inSampleSize=1 

so I use it to surround it by trying an exception from memory, as this is bad practice.

 try{ ......... ...... }catch (OutOfMemoryError e) {} 

an exception from the memory also hit but my question is after I caught this exception, we will

Clearing or reallocating GC heap memory

is there any solution?

I use

System.gc ();

not used please help !!!!!!!

 not even Bitmap also for GridView Orientation i found this exception Clamp target GC heap from 17.333MB to 16.000MB Out of memory on a 140416-byte allocation. 
+8
garbage-collection android memory
source share
1 answer

After 3 days of struggle, I found a solution for non-increasing heap memory using this

I replace all my ImageViews this way

 <com.example.util.SingleShotImageView android:id="@+id/grid_image" android:layout_width="170dp" android:layout_height="240dp" android:adjustViewBounds="true" android:layout_centerInParent="true" /> 

Using this class, I use the onDetachedFromWindow function to clear the heap size of the bitmap image

 public class SingleShotImageView extends ImageView { public SingleShotImageView(Context context) { super(context); } public SingleShotImageView(Context context, AttributeSet attrs) { super(context, attrs); } public SingleShotImageView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } @Override protected void onDetachedFromWindow () { setImageDrawable(null); setBackgroundDrawable(null); setImageBitmap(null); System.gc(); } } 

now it works fine and my heap memory remains

Increase the heap (fragment) to 11.719 MB to allocate 8192016 bytes

+11
source share

All Articles