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

Problems with disposing texture when using video, also memory leak #2

Open
Kabaril opened this issue Aug 17, 2019 · 6 comments
Open
Assignees

Comments

@Kabaril
Copy link

Kabaril commented Aug 17, 2019

There is no texture.Dispose() called in the Draw method in the VideoPlayback Demo for DesktopGL
I noticed that the memory usage of the program goes up linearly
When I added said Dispose call, there was a System.NullReferenceException
in FFmpegHelper Line 230

Same for the Code in the Readme in Monogame.Extended.VideoPlayback

@hozuki
Copy link
Owner

hozuki commented Aug 18, 2019

You should not dispose the texture you got from GetTexture(). (You shouldn't do it in XNA either.) This is stated in the documentation. The demo code in readme is an earlier version, which creates a new texture in every call. That behavior was not compatible with XNA, so I changed it, but forgot to update readme. I'll update readme and fix that code.

For the memory leak, I'll look into the problem.

@hozuki
Copy link
Owner

hozuki commented Aug 25, 2019

I cannot reproduce memory leak here.

I used a 1080p 60 FPS video (~2 min, plus multiple times of replaying) to test its performance under high pressure. When opening the video it takes ~81 MB (baseline). The highest memory usage recorded was +~10 MB (on replaying), and the average usage was +~5 MB. Seconds after replaying a GC was triggered and the usage falled back to average.

@hozuki hozuki self-assigned this Nov 23, 2019
@hozuki
Copy link
Owner

hozuki commented Nov 23, 2019

Hmmm while playing the demo video, memory leak is observed...

@hozuki
Copy link
Owner

hozuki commented Nov 23, 2019

Can you test the latest commit aa5d9a5?

@gsenly
Copy link

gsenly commented Jan 30, 2020

Found memory leak in AudioDecodingContext.cs in Dispose the _resampleContext was close but not freed. When new video loaded the closed resampleContext was not freed by ffmpeg.
protected override void Dispose(bool disposing) {
if (_resampleContext != null) {
var resampleContext = _resampleContext;
ffmpeg.swr_close(_resampleContext)
Added ffmpeg.swr_free(&resampleContext);
_resampleContext = null;
}

        if (_codecContext != null) {
            ffmpeg.avcodec_close(_codecContext);
            _codecContext = null;
        }

        // Will be freed by AVFormatContext
        _audioStream = null;
    }

@hozuki
Copy link
Owner

hozuki commented Feb 18, 2020

Found memory leak in AudioDecodingContext.cs in Dispose the _resampleContext was close but not freed. When new video loaded the closed resampleContext was not freed by ffmpeg.
protected override void Dispose(bool disposing) {
if (_resampleContext != null) {
var resampleContext = _resampleContext;
ffmpeg.swr_close(_resampleContext)
Added ffmpeg.swr_free(&resampleContext);
_resampleContext = null;
}

        if (_codecContext != null) {
            ffmpeg.avcodec_close(_codecContext);
            _codecContext = null;
        }

        // Will be freed by AVFormatContext
        _audioStream = null;
    }

Thanks, it helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants