[Magnifier-44] Fix memory leak caused by callback
Before this CL, the magnifier could have caused a memory leak when: - in Editor we give the magnifier a callback that updates the visibility of the handles after the magnifier is drawn. This holds a reference to the HandleView, which in turn has a reference to the containing Activity - the callback is set on the InternalPopupWindow, in order to be run after the next #doDraw call - #doDraw is post'd as a runnable to the UI thread - the magnifier is dismissed and the activity is destroyed - when the garbage collection happens, the InternalPopupWindow cannot be collected, because either: -- there is still a reference to the job expected to run #doDraw -- there is still a pixel copy that has to finish. We keep a reference to the InternalPopupWindow in use when the pixel copy was requested in order to compare it with the current one, and dismiss the pixel copy result if the instance has changed - both options above mean that we will still have a reference to the callback that sets the visibility of the handles, so a reference to the containing Activity. The Activity is, therefore, leaked. This CL cleares the handle visibility callback when the magnifier is dismissed, such that the unnecessary reference to the Activity will not be held. Bug: 80279783 Test: verified with leakcanary that the memory leak no longer exists Change-Id: I65c77eb12d2778c76fe631b55e6a7164fbf487f1
Loading
Please register or sign in to comment