Drawable vs Single reusable Bitmap better with memory?

后端 未结 2 411
情深已故
情深已故 2020-12-08 07:59

As I understand it (not that I\'m correct) Drawables are generally correctly removed from memory when the application is finished with them. Bitmaps however need to be manua

2条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-08 08:27

    I back Romain's proposal, but I'm not sure your question is addressing your actual problem. I don't know how you handle the references to your Views. Maybe you simply have memory leaks in your application? A lot of memory leaks in Android are related to Context. When a Drawable is attached to a View, the View is set as a callback on the Drawable.

    TextView myView = new TextView(this);
    myView.setBackgroundDrawable(getDrawable(R.drawable.my_bitmap));
    

    In the code snippet above, this means the Drawable has a reference to the TextView which itself has a reference to the Activity (the Context) which in turns has references to pretty much anything depending on your code.

    Without looking at more of your code I guess you're on the right track by setting the stored drawables' callbacks to null when an Activity is destroyed.

提交回复
热议问题