javacv
javacv copied to clipboard
linux-arm64 grabber.close() the memory do not release
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()));
}
On Linux, we may need to call Pointer.trimMemory() to release the memory to the system.
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
If you're looking for the API documentation, it's available here: http://bytedeco.org/javacpp/apidocs/org/bytedeco/javacpp/Pointer.html#trimMemory--
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
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
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.
I meet the same problem, how did you solved this problem?