FFmpegMediaMetadataRetriever icon indicating copy to clipboard operation
FFmpegMediaMetadataRetriever copied to clipboard

Native Memory Leak in Android

Open jamesguoxin opened this issue 7 years ago • 4 comments

We are using this code to load video and process frames with OpenCV. A simple example is as following:

FFmpegMediaMetadataRetriever mmr = new FFmpegMediaMetadataRetriever(); mmr.setDataSource(mUri); mmr.release();

Then we start to process one thousand videos to test our mobile algorithm, but according to Android Profiler, the native memory goes to infinity and our app crushed after a few runs. We suspect that FFmpegMediaMetadataRetriever release method doesn't work as it expected. We've tried to pinpoint the exact problem, however, we didn't have a clue. It would be much appreciated if anyone could land a hand. Thanks!!!!

jamesguoxin avatar Aug 29 '18 11:08 jamesguoxin

I met this error too, if you solve it , please help me ~

dancingpipi avatar Jan 10 '19 09:01 dancingpipi

I think it could be that you're not waiting for the process to finish before releasing it and starting it again. Use an AsyncTask then in onPostExecute release FFmpegMediaMetadataRetriever then pass the next path until completed.

When you call FFmpegMediaMetadataRetriever repeatedly without waiting for processes to finish will cause out of memory exception (memory leak).

HBiSoft avatar Jul 26 '19 18:07 HBiSoft

How is it possible to know when it has completed, in a for loop of items to process? How is the stup of the AsyncTask? Considering, am already doing this heavy work in a background thread, but it still seems to hog onto memory the more items I have in the list to process.

RowlandOti avatar Dec 12 '19 11:12 RowlandOti

I conclude that since the object des did not have a Singleton, it will lead to several of class objects created having different instances. This would quickly lead to OOM.

RowlandOti avatar Jan 10 '20 11:01 RowlandOti