I use javacv in android project,to push live stream from two cameras,but an "OOM" problem occured after long time.
I analysed the memory by android studio tools, find that,"native" occupied 7M at the begin, but after an hour,it occupied 30M+.
What can i do to recycle this part of memory?
when oom happened,
"ion: mmap failed: Out of memory"
"E/vpu_dma_buf: vpu_dmabuf_alloc:216: ion map failed"
will be found in log
Looks like you're running out of memory. It's always possible there's a memory leak. What does the profiler say about allocated Java objects, for starters?
I can`t find how to post pic on github-issue.Today my app keeps running for 10 hours,also the "native" memory increased from 8M to 139M including to the profiler.
"Other" 0.68M,
"Code" 12.81M,
"Stack" 0.43M,
"Graphics" 0M
"Native" 139.59M
"Java" 13.95M
I click into "Memory" and record memory allocations,find that there is a ClassName of"byte[]",shallow size is biggest,it has many instance of "byte[]",its shallow size is 460812,it looks like near to the param "byte[] data" of the Camera method "onPreviewFrame" (460800 perhaps).
It is the "allocated Java objects" you mean?
the error "ion: mmap failed: Out of memory" maybe a hardware error of vpu as my hardware friend said.
but the issue of memory keeping increasing still exists,it may prevent my app keeping-running-unmanned.
Could you help me analyse the problem,or tell me how to recycle this part of memory?
Ah, you're not reusing your preview buffers, as shown in this sample project:
https://github.com/bytedeco/sample-projects/blob/master/javacv-android-camera-preview/app/src/main/java/org/bytedeco/javacv/android/example/CvCameraPreview.java#L550
https://github.com/bytedeco/sample-projects/blob/master/javacv-android-camera-preview/app/src/main/java/org/bytedeco/javacv/android/example/CvCameraPreview.java#L734
Make sure you do and that will solve your problem.
you mean that "
// [IMPORTANT!] remember to reset the CallbackBuffer at the end of every onPreviewFrame event.
// Seems weird, but it works
cam.addCallbackBuffer(previewBuffer);
"
I will try!Thank you! Also I will review this sample wholely and carefully!
Please thank @hnvn!
Yes,of caurse! You and hnvn both help me and tell this point important for me.
I try "setPreviewCallbackWithBuffer",but it seems not work.
the "native" occupied memory increases from "18M" to "20.9M" for 11 miutes.And the data of "Allocated" keep increasing before GC. Before "setPreviewCallbackWithBuffer",the data of "Allocated" keeps 5000.
There is any wrong in my code? I will keep watching this.
before "mCamera.startPreview();" I add this:"
cameraDevice.addCallbackBuffer(previewBuffer);
mCamera.setPreviewCallbackWithBuffer(CameraView.this);"
After processFame in "onPreviewFrame",I add this:"
camera.addCallbackBuffer(previewBuffer);
"
So there might be native memory leaking, sure.
We could debug that with either Valgrind or AddressSanitizer:
https://source.android.com/devices/tech/debug/valgrind
https://source.android.com/devices/tech/debug/asan
What can I do for native memory leaking ?
If it needs to edit C# files,it is too hard for me.
These two urls can`t be accessed for me, I will find them in other way.
You could start by making modifications to FFmpegFrameRecorder to find which function calls cause the leak. This does not require doing anything in C++. You only need to touch Java code. When you find which functions are causing the issue, the solution should become clear.
OK,I will try!
Marking as duplicate of issue #911
I think I've fixed all the memory leaks occurring in FFmpegFrameGrabber and FFmpegFrameRecorder.
Please give it a try with the snapshots: http://bytedeco.org/builds/