Is it safe to view links to activity displaying it?

I expanded the View and passed it an instance of my Activity so that the view can access some member variables and methods.

But now I think it could be a potential memory leak, because even after the Activity is destroyed, it still has a reference to the view in the member variable and vice versa. Therefore, the garbage collector can never clean them.

However, I saw in some examples and examples of the Google API APIs where they passed Activity in the view as a listener.

+3
source share
2 answers

, , , , - , , - this . . View, getContext().

, , GC . onDestroy, , , .. . GC Views. , , , Activity, , GC pass .

+6

View , . , , .

+3

Source: https://habr.com/ru/post/1791482/


All Articles