RootEncoder icon indicating copy to clipboard operation
RootEncoder copied to clipboard

recording increase memory usage but not release in time

Open xumingxin7398 opened this issue 3 years ago • 17 comments

I just use your code and your example. Click OpenGl Rtsp and "start record" button. Use adb command "adb shell" and then "free -m" every few minutes to check the free memory. The logcat shows BufferPoolAccessor2.0 com.pedro.rtpstreamer D bufferpool2 0xb4000075d7f32a48 : 5(20480 size) total buffers - 4(16384 size) used buffers - 68387/68392 (recycle/alloc) - 100/136775 (fetch/transfer) Any idea to release memory in time or manually to do it better?

微信截图_20220630125010 微信截图_20220630130438

.

xumingxin7398 avatar Jun 30 '22 05:06 xumingxin7398

After recording for hours, the device's memory was down to 20M even less. It would cause a lot of problems because no memory to do other things.

xumingxin7398 avatar Jun 30 '22 05:06 xumingxin7398

Hello,

Are you using library without odifications? Can you reproduce the case only for rtsp or you can reproduce it using rtmp?

pedroSG94 avatar Jun 30 '22 06:06 pedroSG94

No any odifications. Only use the recording feature under OpenGl Rtsp. You can try by my step with the demo code. The code I used was download by "git clone https://github.com/pedroSG94/rtmp-rtsp-stream-client-java" about last week.

xumingxin7398 avatar Jun 30 '22 06:06 xumingxin7398

Can you tell me more or less a time when you can notice that memory increase? About 30min es enought to test and check differences? If you are only streaming, Do you get that memory problems or it is only for recording case? Meanwhile try using rtmp to discard rtsp module of this case

pedroSG94 avatar Jun 30 '22 06:06 pedroSG94

Every 1 minute or 2 minute can see the changes of free memory. I did't start rtmp or rtsp streaming, just start the record button and keep it recording for minutes. It's easy to find the memory changed, don't need to test a lot. About half an hour, the free memory was down from 200M to 50M.

xumingxin7398 avatar Jun 30 '22 06:06 xumingxin7398

Even I stop the application and restart the application, the memory was not recycled. But only I shutdown the device and restrat the device, the memory comes back. So I think is some native recources not be release,need your help for my poor in native code.

xumingxin7398 avatar Jun 30 '22 07:06 xumingxin7398

Hello,

I'm not using native code. All the code use Android java SDK. Anyway, I will check it and let you know results

pedroSG94 avatar Jun 30 '22 10:06 pedroSG94

What I know is that the buffers in native maybe not cleard and recycled, because after I stop the application, the buffers count in below is not decrease. 微信截图_20220630190710 .

xumingxin7398 avatar Jun 30 '22 11:06 xumingxin7398

Hi, brother. Any idea? I think this is a big issue of this lib, it makes me confused a lot.

xumingxin7398 avatar Jul 01 '22 14:07 xumingxin7398

Hello,

I was doing tests but I can find the reason. For now I'm testing using this: https://square.github.io/leakcanary

pedroSG94 avatar Jul 02 '22 16:07 pedroSG94

I had done this test with leakcanary yet, it does'nt work for this case. Leakcanary is good at java code like ui and variable but can't monitor the navite memory like linux buffers. Just connect your phone using USB and open develop mode, then use adb command to find out the problem. I found some code like ByteBuffer and BufferQueue in your job, maybe we need to release them in time.

xumingxin7398 avatar Jul 02 '22 16:07 xumingxin7398

Can you check "ByteBuffer.allocateDirect" in your code? what I know is this method will keep memory in native but not in jvm, so it would be hard to release. I search this words in the code, every filter and render use this function, maybe it's the reason. ByteBuffer.allocate() and ByteBuffer.allocateDirect() is different, how about use ByteBuffer.allocate() to replace ByteBuffer.allocateDirect()?

xumingxin7398 avatar Jul 02 '22 16:07 xumingxin7398

According with Android studio it isn't native memory: record start record end

pedroSG94 avatar Jul 02 '22 16:07 pedroSG94

Now, I'm using Android studio profiler to get any hint.

pedroSG94 avatar Jul 02 '22 16:07 pedroSG94

Can you check "ByteBuffer.allocateDirect" in your code? what I know is this method will keep memory in native but not in jvm, so it would be hard to release. I search this words in the code, every filter and render use this function, maybe it's the reason. ByteBuffer.allocate() and ByteBuffer.allocateDirect() is different, how about use ByteBuffer.allocate() to replace ByteBuffer.allocateDirect()?

I can't do it because opengl need an allocateDirect. Anyway, this can't be the problem because it is called only a time when you init filter in each filter and I can see the problem without filters.

pedroSG94 avatar Jul 02 '22 18:07 pedroSG94

Thanks a lot, I will make more tries until this problem being fixed.

xumingxin7398 avatar Jul 02 '22 22:07 xumingxin7398

I will mark this as help wanted for now and try to fix the problem. If you find the way to solve this problem any PR will be welcome.

pedroSG94 avatar Jul 03 '22 17:07 pedroSG94