Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: shouldn't all instances of Pointer be deallocated to release native memory? #1337

Closed
netbrain opened this issue Nov 20, 2019 · 6 comments

Comments

@netbrain
Copy link

I see that this is not the case for this line, is this causing a memory leak?

&& new Pointer(frame.image[0].position(0)).address() == img.imageData().address()

@netbrain
Copy link
Author

Also i can't seem to find any release of memory for these two lines:

this.video_pkt = new AVPacket();
this.audio_pkt = new AVPacket();

Im guessing the releaseUnsafe method should call av_free_packet()?

@saudet
Copy link
Member

saudet commented Nov 21, 2019

The first one doesn't cause allocation of any native memory, so that's alright.

As for video_pkt and audio_pkt, the default allocator registers a deallocator for the garbage collector to call at some point after they become unreachable. We could deallocate them explicitly on release, but they won't cause a memory leak.

Are you having any issues with a memory leak somewhere?

@netbrain
Copy link
Author

Well, im not sure. I think maybe I have fixed it, but needs further testing :) Any hints for how to track down memory leaks in JNI? so far I have tried BCC's memleak utility. but all in all, allocations looks fairly good. I've also tried using AspectJ and instrumenting JavaCPP's Pointer class and spying on set on the address field and using that information to create a summary of allocs & deallocs, not the greatest set of results though.. Haven't tried valgrind yet, but i guess that will be next if i still see crashes due to memory.

@saudet
Copy link
Member

saudet commented Nov 22, 2019 via email

@saudet
Copy link
Member

saudet commented Jun 18, 2020

BTW, 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/

@saudet
Copy link
Member

saudet commented Sep 10, 2020

PointerBufferPoolMXBean from @matteodg released with JavaCPP 1.5.4 should make it easier to debug.
If you still have issues with this though, please let me know!

@saudet saudet closed this as completed Sep 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants