A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/bytedeco/javacpp-presets/issues/878 below:

Memory leak · Issue #878 · bytedeco/javacpp-presets · GitHub

I'm struggling with a memory leak whilst calling certain ffmpeg functions.

The following code is an example, the problematic function call (av_guess_frame_rate) is commented out, without this line I can call this code many thousands of times without any signs of leak. With this line there is a steady increase in memory consumption and calls to Pointer.totalBytes() see an increase in 8 bytes per call.

I'm guessing that for some reason the AVRational is not being cleaned up. Running under the debugger the dealocator does appear to be called at the end of the try block.

Is there something else that I need to be doing here? I've tried all sorts of combinations of fr.releaseReference(), fr.deallocate(), fr.close() and Pointer.deallocateReferences().

I've also tried modifying the example program ReadFewFrame to run in a loop. That program takes only a few minutes to grab the maximum allowed memory before crashing.

My maven dependency is :

<dependency>
    <groupId>org.bytedeco</groupId>
    <artifactId>ffmpeg-platform</artifactId>
    <version>4.2.2-1.5.3</version>
</dependency>

I'm running under Amazon Corretto 11.0.6_10 on Windows 10.

    public void test(String filename) {

        try (PointerScope scope=new PointerScope()) {
            AVFormatContext ifmtCtx =  new AVFormatContext(null);
            int rv;

            rv = avformat_open_input(ifmtCtx, filename, null, null);
            if(rv < 0) throw new RuntimeException("Could not open input file " + filename+" error="+rv);

            // load stream information
            rv = avformat_find_stream_info(ifmtCtx, (PointerPointer) null);

            AVStream videoStream = null;
            // find the first video stream
            for(int i = 0; i < ifmtCtx.nb_streams(); i++) {
                AVStream stream = ifmtCtx.streams(i);
                int codecType = stream.codecpar().codec_type();
                if(codecType == AVMEDIA_TYPE_VIDEO) videoStream = stream;
            }

            int codecID = videoStream.codecpar().codec_id();
            AVCodec dec = avcodec_find_decoder(codecID);
            if(dec == null)
                throw new RuntimeException("Could not find decoder for stream " + videoStream.index() + " id " + codecID);

            AVCodecContext codecContext = avcodec_alloc_context3(dec);
            if(codecContext == null)
                throw new RuntimeException("Failed to allocate decoder context for stream " + videoStream.index());
            rv = avcodec_parameters_to_context(codecContext, videoStream.codecpar());
            if(rv < 0) throw new RuntimeException("Failed to copy decoder parameters to input decoder error="+ rv);

            // MEMORY LEAK on this line
            //AVRational fr=av_guess_frame_rate(ifmtCtx, videoStream, null);

            avcodec_close(codecContext);
            avcodec_free_context(codecContext);
            codecContext.close();
            codecContext.releaseReference();
            codecContext.deallocate();

            avformat_close_input(ifmtCtx);
            avformat_free_context(ifmtCtx);

        }
    }


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4