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
Bald bcs of IT
source share