memory leak caused by initialize method of YouTubePlayer.Provider
Asked Answered
D

1

9

Using Eclipse Memory Analyzer i discovered that if I go back and forth between 2 activity (e.g. A and B), although onDestroy method of activity B is called, GC never removes it from memory, so I have multiple instances of Activity B in memory. I found that the problem is in initialize method called on YouTubePlayerFragment instance. Here is the code:

YouTubePlayerFragment ytpf =(YouTubePlayerFragment) getFragmentManager().findFragmentById(R.id.youtube_fragment);

ytpf.initialize(DEVELOPER_KEY,this);

this is the the activity where fragment takes place, and implements YouTubePlayer.OnInitializedListener.

How can I release the callback passed on initialize method?

I tried to call youtubePlayer.release() but the problem remains.

Dominus answered 25/11, 2014 at 13:29 Comment(6)
did you solve the issue? With that memory leak YouTube player remains unusableHeritable
Having the same issue, has it been reported to Google ?Kong
I don't use YouTubePlayerFragment anymore, I'm actually using a custom fragment that launch an Intent with YouTubeStandalonePlayerDominus
This still exists, damn googleCopulative
This STILL exists...Can't believe how much time I wasted on it, only to discover it's a bug.Intercept
Any updates for this errorLoudhailer
A
1

I was hit by this leak this week. It seems that Google still hasn't fixed it, regardless of the ticket's status. I made some tests on my initial project, on which the leak is causing an OOM, and on the demo project by Google. My observations are :

  • It's not the listener YouTubePlayer.OnInitializedListener that is causing the leak. When calling YouTubePlayerFragment.initialize(), there are calls in YouTubePlayerFragment getting a reference to the activity that is hosting the fragment. So no luck in trying to call initialize() with an empty and static listener when the fragment is being stopped, hoping that the reference would be cleaned up.
  • While there is a leak for sure, it seems that at some point, there is a cleanup being done. I would go to 18 instances of the same activity, and then the count would drop down to 8 instances. So I guess that for the majority of the cases the leak could go unnoticed.
  • YouTubePlayerFragment& YouTubePlayerView, same leaks.

I don't see any workaround this. I guess I will have to use another implementation, based on a webview like this one : https://github.com/PierfrancescoSoffritti/Android-YouTube-Player

Alleged answered 6/4, 2018 at 21:7 Comment(1)
Any workaroundsLoudhailer

© 2022 - 2024 — McMap. All rights reserved.