Search code examples
javac++jna

c++ memory leak by java's calling


I have a question about memory leak calling c++ in java. If my c++ function has the memory leak problem, when I call it in my java application.

  1. Can I find the problem by JVM tools?
  2. If the memory continuous leaks, java can catch the out of memory exception?
  3. I call the c++ function by JNA way and use the JNA Structure Objects, I need to manage the memory of them by myself.

Solution

    • First of all C++ code run outside the control of JVM so you can't find problem by any JVM tool like JMC.

    • For 2nd OutOfMemoryError is not exception it is an error you can catch it if memory is full inside JVM and still you can't do any think for that after catching that error but here in your case C++ code run outside the JVM this error not directly catch by java you need to handle that in C++ it self.

    • 3rd Yes you have to manage memory by your self.