I have observed that when activity is destroyed then all the instances of the library code are not finished and thus the memory taken by library code isn't released.
Could you please look into it.
Hey, how do you know this is happening?
Feel free to send a pull request.
I use your library as an item in my RecyclerView in an Activity. Maybe you need to check the internal webview.
Below is my LeakCanary info:
ApplicationLeak(className=com.abc.ArticleDetailActivity, leakTrace=
β¬
ββ org.chromium.device.power_save_blocker.PowerSaveBlocker
β Leaking: NO (a class is never leaking)
β GC Root: Global variable in native code
β β static PowerSaveBlocker.b
β ~
ββ java.util.HashMap
β Leaking: UNKNOWN
β β HashMap.table
β ~
ββ java.util.HashMap$Node[]
β Leaking: UNKNOWN
β β array HashMap$Node[].[0]
β ~
ββ java.util.HashMap$Node
β Leaking: UNKNOWN
β β HashMap$Node.key
β ~
ββ com.pierfrancescosoffritti.androidyoutubeplayer.core.player.views.WebViewYouTubePlayer
β Leaking: YES (View.mContext references a destroyed activity)
β mContext instance of com.abc.ArticleDetailActivity with mDestroyed = true
β View#mParent is null
β View#mAttachInfo is null (view detached)
β View.mWindowAttachCount = 2
β β WebViewYouTubePlayer.mContext
β°β com.abc.ArticleDetailActivity
β Leaking: YES (WebViewYouTubePlayerβ is leaking and Activity#mDestroyed is true and ObjectWatcher was watching this)
β key = 4ee2961d-1584-4a7a-8eab-d2c91687a56a
β watchDurationMillis = 6575
β retainedDurationMillis = 1567
, retainedHeapByteSize=295071)
Hello,
This problem can be reproduced in Sample App.
After adding debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.0-beta-3' into build.gradle of core-sample-app, launch "ayp API" and click "Fragment Example". Then press back key to go back to main page. You will see leakcanary reports the leak(refer to the attachment).

Thanks for the info. These days I don't have much time to work on the library, pull requests are welcome!
I use your library as an item in my RecyclerView in an Activity. Maybe you need to check the internal webview.
Below is my LeakCanary info:
ApplicationLeak(className=com.abc.ArticleDetailActivity, leakTrace=
β¬
ββ org.chromium.device.power_save_blocker.PowerSaveBlocker
β Leaking: NO (a class is never leaking)
β GC Root: Global variable in native code
β β static PowerSaveBlocker.b
β ~
ββ java.util.HashMap
β Leaking: UNKNOWN
β β HashMap.table
β~
ββ java.util.HashMap$Node[]
β Leaking: UNKNOWN
β β array HashMap$Node[].[0]
β~
ββ java.util.HashMap$Node
β Leaking: UNKNOWN
β β HashMap$Node.key
β ~
ββ com.pierfrancescosoffritti.androidyoutubeplayer.core.player.views.WebViewYouTubePlayer
β Leaking: YES (View.mContext references a destroyed activity)
β mContext instance of com.abc.ArticleDetailActivity with mDestroyed = true
β View#mParent is null
β View#mAttachInfo is null (view detached)
β View.mWindowAttachCount = 2
β β WebViewYouTubePlayer.mContext
β°β com.abc.ArticleDetailActivity
β Leaking: YES (WebViewYouTubePlayerβ is leaking and Activity#mDestroyed is true and ObjectWatcher was watching this)
β key = 4ee2961d-1584-4a7a-8eab-d2c91687a56a
β watchDurationMillis = 6575
β retainedDurationMillis = 1567
, retainedHeapByteSize=295071)
same problem with me

how to resolve it?
I'm also seeing the same issue reported by Logcat on Android Studio. A workaround that seems to work is to override onStop in my fragment as follows
override fun onStop() {
super.onStop()
youtubePlayerView.release()
}
I understand this is not the best option as I'm doing more than needed but at least it unregisters the networkListener
Proposed fix is to simply call context.unregisterReceiver(networkListener) in the onStop method of LegacyYoutubePlayerView ...
@PierfrancescoSoffritti I have created a PR for a proposed fix... this is my 1st PR ever to an open-source project so I hope I'm doing things right.
Regards,
Adam
Most helpful comment
I'm also seeing the same issue reported by Logcat on Android Studio. A workaround that seems to work is to override onStop in my fragment as follows
I understand this is not the best option as I'm doing more than needed but at least it unregisters the
networkListenerProposed fix is to simply call
context.unregisterReceiver(networkListener)in theonStopmethod ofLegacyYoutubePlayerView...@PierfrancescoSoffritti I have created a PR for a proposed fix... this is my 1st PR ever to an open-source project so I hope I'm doing things right.
Regards,
Adam