Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory leak #1855

Closed
tonggang1308 opened this issue Sep 24, 2016 · 9 comments
Closed

Memory leak #1855

tonggang1308 opened this issue Sep 24, 2016 · 9 comments

Comments

@tonggang1308
Copy link

tonggang1308 commented Sep 24, 2016

  • Memory Leak.
  • I modify the ExoPlayer demo app(r2.0.0), let it to play local mp4 file. It is OK, it play very smooth. But, when exit the activity, the memory don't restore to normal level. Even though I force the GC, the memory is not released.
  • The issue can be reproduced at many android device.
@philipgiuliani
Copy link

philipgiuliani commented Sep 26, 2016

I have upgraded my own project to ExoPlayer 2.0 and even calling player.release() does not release any resources. I am streaming mp4 files.

After opening the player a second time with a mp4 file, it crashes with an OutOfMemory exception.

@ojw28
Copy link
Contributor

ojw28 commented Sep 26, 2016

Please can you provide more information on how this is reproduced in the ExoPlayer demo app?

When I exit the playback activity and force 2x GCs via Android Monitor in Android Studio, the memory level reliably returns to its base level (I'm unsure why 2x GCs are required, but that's more likely a property of how the GC works than of ExoPlayer).

Also, if you do multiple playbacks successively, does the memory level increase indefinitely? I would expect that to happen (eventually resulting in an OutOfMemory failure) if there were genuinely a leak. Please clarify. Thanks!

@tothvoj-gl
Copy link

Try simpleExoPlayerView.setPlayer(null); in your onDestroy() method.

@philipgiuliani
Copy link

philipgiuliani commented Oct 3, 2016

I am using an instance of SimpleExoPlayer without the SimpleExoPlayerView. The memory drops a little bit when opening the next instance of a player. After 3-4 times it crashes because of OutOfMemory.

I have not tried the demo app, but thats how the memory graph looks in my application:

leak

The memory always increases, it never goes back.

 @Override
public void onDestroy() {
    super.onDestroy();
    releasePlayer();
}

private void releasePlayer() {
    if (mPlayer != null) {
        mPlayer.stop();
        mPlayer.release();
        mPlayer = null;
    }
}

@Override
public void surfaceDestroyed(SurfaceHolder surfaceHolder) {
    if (mPlayer != null) {
        mPlayer.setVideoSurfaceHolder(null);
    }
}

Do i have to call something else?

@ojw28
Copy link
Contributor

ojw28 commented Oct 3, 2016

Please try with the demo app. Without further information, the memory leak you're seeing could be caused by anything in your application. A graph like the one above is not sufficient evidence the leak is ExoPlayer's fault.

As long as you're releasing the player and nulling the reference to it, that should be sufficient. You should do it before onDestroy though; doing it there is too late. You should be releasing resources in onPause, or onStop if the SDK version is 24 or higher. This is what the demo app does.

ojw28 added a commit that referenced this issue Oct 3, 2016
This prevents a large amount of memory from being held
in the case that a player instance is released, but the
application is holding dangling references to the player
that are preventing it from being garbage collected.

Issue: #1855

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=134992945
@ojw28
Copy link
Contributor

ojw28 commented Oct 3, 2016

We've pushed a change to dev-v2 that will release memory proactively when release is called on the player.

Note however that you will only be experiencing this issue in the first place if you're leaking the player instance. We're unable to reproduce this problem in the demo app, and suspect that it's an issue in your own application code. You should work out where this leak is and fix it, since although our change will significantly reduce the size of the leak, the leak will still be there and you may be leaking other objects too.

@ojw28 ojw28 closed this as completed Oct 3, 2016
ojw28 pushed a commit that referenced this issue Oct 6, 2016
…layer is released.

Without this developers which reuse a SurfaceHolder with multiple instances of
SimpleExoPlayer need to call simpleExoPlayer.setVideoSurfaceHolder(null) to get
the SimpleExoPlayer.ComponentListener removed from the surface holder. If they
don't, the component listener is still registered and as a member class leaks
an instance of simpleExoPlayer.

Issue #1855

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=135292439
@PerkmannM
Copy link

I'm experiencing the same problem with ExoPlayer 2.0.0 in my own project.
Due to this problem I created a new project with the most simple ExoPlayer setup, just to see if the memory still leaks.
And actually it really does.

This app provides four buttons with four different dummy .mp4 files.
By switching them continuously I managed to generate a memory graph like this.

In my opinion the player stops releasing memory after I included the controls.

Could you please check my project and tell me where my problem is?
Thank you!

bildschirmfoto 2016-10-06 um 17 01 45

https://github.com/PerkmannM/Demo-ExoPlayer

@ojw28
Copy link
Contributor

ojw28 commented Oct 7, 2016

Thanks for the very helpful reproduction steps. I've filed #1908 to track this issue. I'll also post a workaround there.

@akhilesh006
Copy link

Hi @PerkmannM , I am also facing the same issue with Google Media Framwork, It is internally using Exo Player 1.5.7. Could you please help me if you have resolved the issue as I couldn't track.

@google google locked and limited conversation to collaborators Jun 28, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants