javacv icon indicating copy to clipboard operation
javacv copied to clipboard

linux-arm64 grabber.close() the memory do not release

Open wangjia5693 opened this issue 1 year ago • 7 comments

as the title describe ,i use Pointer.formatBytes(Pointer.physicalBytes()) to mark the memory usage , when i call the grabber.close() and record.close(), in my macos,it release the memory ,but in linux-arm64 ,it can't

system: Linux version 4.9.201-tegra (rich@Vostro-5490) (gcc version 7.3.1 20180425 [linaro-7.3-2018.05 revision d29120a424ecfbc167ef90065c0eeb7f91977701] (Linaro GCC 7.3-2018.05) )

  FFmpegFrameGrabber grabber = new FFmpegFrameGrabber("rtsp://admin:[email protected]:554/h264/ch41/main/av_stream");
        grabber.start();
        FFmpegFrameRecorder recorder = new FFmpegFrameRecorder("/data/ffmpeg/id-%03d.png", 1080, 720, 0);
        recorder.setFormat("image2");
        recorder.setOption("update", "0");
        recorder.start();
        try {
            Frame frame = null;
            int i = 0;
            for (; (frame = grabber.grabImage()) != null; ) {
                try {
                    recorder.record(frame);
                    i++;
                    if (i > 6) {
                        break;
                    }
                } catch (org.bytedeco.javacv.FrameRecorder.Exception e) {
                    e.printStackTrace();
                }
            }
        } finally {
            log.info("before:{}", Pointer.formatBytes(Pointer.physicalBytes()));
            grabber.close();
            recorder.close();
            log.info("after:{}", Pointer.formatBytes(Pointer.physicalBytes()));
        }

wangjia5693 avatar Jul 25 '22 08:07 wangjia5693

On Linux, we may need to call Pointer.trimMemory() to release the memory to the system.

saudet avatar Jul 25 '22 11:07 saudet

On Linux, we may need to call Pointer.trimMemory() to release the memory to the system.

thank you for you help ,i will have a try ; but i am a beginner of this,can you give me a demo or more reference of this, thanks a lot

wangjia5693 avatar Jul 25 '22 12:07 wangjia5693

If you're looking for the API documentation, it's available here: http://bytedeco.org/javacpp/apidocs/org/bytedeco/javacpp/Pointer.html#trimMemory--

saudet avatar Jul 25 '22 12:07 saudet

If you're looking for the API documentation, it's available here: http://bytedeco.org/javacpp/apidocs/org/bytedeco/javacpp/Pointer.html#trimMemory--

i am not very clear,Pointer.trimMemory() is a static private method ,how can i call it

wangjia5693 avatar Jul 26 '22 01:07 wangjia5693

Right, it's a private method. It's not something users usually need to worry about. It currently only does something on Linux, and just essentially calls malloc_trim(). In any case, please try to make it public and see if that does what you want it to do. If it works, please open a pull request with the requested changes: https://github.com/bytedeco/javacpp/pulls

saudet avatar Jul 26 '22 09:07 saudet

It's also possible that your version of the JDK calls malloc_trim() on System.gc(), so you could also try to call that and see if it does what you need.

saudet avatar Jul 26 '22 09:07 saudet

I meet the same problem, how did you solved this problem?

Vansonccc avatar Aug 08 '22 01:08 Vansonccc