Open kazemihabib opened 7 years ago
I'm experiencing this same problem. Working on a solution where I instantiate and set those libVLC Android objects null. Let me know if you find any solutions.
I think there is a leak in 2.1.12 as well and this is how I reproduce.
Looping the same video forever produces an observable memory leak. In 35 minutes, memory has grown up 20 MB. Let the player go and it will crash in the future.
Here is a createPlayer function inside a VideoActivity :
if(libvlc == null)
libvlc = new LibVLC(this, options);
PlayerListener mPlayerListener = new PlayerListener(this,mediaPath);
mMediaPlayer = new MediaPlayer(libvlc);
mMediaPlayer.setEventListener(mPlayerListener);
// Set up video output
final IVLCVout vout = mMediaPlayer.getVLCVout();
vout.setVideoView(mSurface);
vout.addCallback(this);
vout.attachViews();
Media m = new Media(libvlc, media);
mMediaPlayer.setAspectRatio("16:9");
mMediaPlayer.setMedia(m);
mMediaPlayer.play();`
And here a playerListener object :
private static class PlayerListener implements MediaPlayer.EventListener {
private WeakReference<VideoActivity> mOwner;
private String mFilePath;
public PlayerListener(VideoActivity owner, String mFilePath) {
mOwner = new WeakReference<VideoActivity>(owner);
this.mFilePath = mFilePath;
}
public void onEvent(MediaPlayer.Event event) {
VideoActivity player = mOwner.get();
switch(event.type) {
case MediaPlayer.Event.EndReached:
Log.d(TAG, "MediaPlayerEndReached");
player.mMediaPlayer.stop();
player.mMediaPlayer.setPosition(0);
player.mMediaPlayer.play();
break;
case MediaPlayer.Event.Playing:
case MediaPlayer.Event.Paused:
case MediaPlayer.Event.Stopped:
default:
break;
}
}
}
` Note : These parts of code are inspired from edwardcw, which is reffered to in VideoLAN wiki page LibVLC on Android
Apparently the VLC native objects cannot be re-used without causing memory leaks. By destroying them at each media end, the memory gets more stable. I'm currently testing this approach and am confident that this solves the problem.
@vdegrandpre what exactly are you destroying?
Hey @anonym24 basically there are 2 things here.
Even the simpliest use case (one video looping to infinity) causes a native memory growth that would eventually overflow.
Destroying/releasing everything helps but does not resolve.
Best, V.
@vdegrandpre isn't media released when you call MediaPlayer.stop()
method? I don't think we should manually release it
also I don't think that official VLC Android app releases MediaPlayer and LibVLC every time video track is changed
they do something else and there are no memory issues
@vdegrandpre I made a test class from LibVLC sample to analyze native memory leaks and releasing MediaPlayer
or LibVLC
doesn't help:
https://code.videolan.org/videolan/vlc-android/issues/580
so I have no idea how to solve this issue
My guess is that, depending on your device, it may also be an OMX resources that is not freed correctly or the like. Because OMX is used in many-many technologies nowadays, that may be the issue. I'll follow the ticket you opened on videolan.org.
Best, V.
I think in new version 2.0.6 there is a memory leak. Is any one else had this problem?