Answer the question
In order to leave comments, you need to log in
Memory leak in LinearLayout's Background, how to fix?
private LinearLayout bg;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
bg = (LinearLayout)findViewById(R.id.bg);
if(bg.getBackground() == null)
{
// На этом поле
Bitmap bitmap = Bitmap.createBitmap(w, h, Bitmap.Config.RGB_565);
bitmap.eraseColor(colorBg);
//radGrad(bitmap);
//drawCircles(bitmap);
bg.setBackground(new BitmapDrawable(this.getResources(), bitmap));
}
}
Answer the question
In order to leave comments, you need to log in
There is no explicit object deletion in Java. Instead, there's garbage collection. If you assign null to an object reference, then the object will still be in memory for some time, until the collector finally removes it. Deletion time is not defined. Judging by the code, the Bitmap will be created every time a new activity is created. For example, if you twist the phone: when you change the layout, the activity is deleted and recreated. If the pictures are large, then you can quickly eat out all the memory. The first solution that came to mind was to store resources like these pictures in a separate class. Download them as needed, checking the fact of their availability. It is not worth storing resources in activity classes.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question