문제

Right now i am reading Roman's Guy tutorial Avoid memory leak, there is the following sentence:

Drawable is attached to a view, the view is set as a callback on the drawable. In the code snippet above, this means the drawable has a reference to the TextView` , Text in webpage .

How to find that drawable has a reference to the Context or not ?

도움이 되었습니까?

해결책

In this case the problem is that the drawable instance is stored statically in a class (so it will never get garbage collected) and it keeps a reference to an activity, which means the activity won't be garbage collected as well (even if it's terminated). Hence the memory leak.

In your debugger you could inspect the drawable instance and see if there is any field that references another view/context.

But just avoid storing UI stuff statically and it will solve a lot of issues like that :)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top