android-youtube-player icon indicating copy to clipboard operation
android-youtube-player copied to clipboard

ConnectivityManger leaks the context on Android 12

Open frett opened this issue 2 years ago • 2 comments

the context object getSystemService() is called on is leaked via ConnectivityManager.sInstance

frett avatar Nov 04 '21 16:11 frett

Hi, thanks for the PR. How is your patch different from the previous implementation?

PierfrancescoSoffritti avatar Nov 05 '21 06:11 PierfrancescoSoffritti

Screen Shot 2021-11-05 at 9 22 48 AM

Here is a debugger stack trace of when the ConnectivityManager.sInstance variable is being set with a ConnectivityManager instance that references an Activity context. The context object that is passed into the NetworkListener.onReceive() method is the activity context class, and not the application context class. So, getting the applicationContext out of the Activity before getting the ConnectivityManager service will prevent the Activity leaking via the sInstance static variable.

This stack trace is from a Pixel 4a running Android 12, I haven't tried running it on older versions of Android yet to determine if the leak was present before or if it's a new leak in Android 12

frett avatar Nov 05 '21 13:11 frett

Hi @frett , I am sorry for the very very late reply. As the single maintainer of the lib it's sometimes hard to keep up with everything going on.

Your PR is correct, the Context was indeed leaked. I have fixed this recently, see #924. Again sorry for not addressing this sooner.

PierfrancescoSoffritti avatar Mar 19 '23 16:03 PierfrancescoSoffritti