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.
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 :
YouTubePlayer.OnInitializedListenerthat is causing the leak. When callingYouTubePlayerFragment.initialize(), there are calls inYouTubePlayerFragmentgetting a reference to the activity that is hosting the fragment. So no luck in trying to callinitialize()with an empty and static listener when the fragment is being stopped, hoping that the reference would be cleaned up.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