0

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.
Slaw
  • 37,820
  • 8
  • 53
  • 80
Jianfeng
  • 5
  • 1
  • Try avoiding memory allocations in C++, and when needed use the standard classes like unique_ptr to make life so much easier. See https://stackoverflow.com/a/53898150/2466431 for more details – JVApen Dec 28 '18 at 07:40

1 Answers1

0
  • 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.

Sunil Kanzar
  • 1,244
  • 1
  • 9
  • 21