Would Java Native Interface objects instantiated in C++ appear in the ANTS Profiler as C++ leaks

We have a web application that calls into a C++ component.  The C++ component uses a JNIEnv_ pointer to make calls to CallObjectMethod in the Java Virtual Machine.  In each case the pointers returned get assigned to local objects of types such as jobject and jstring.  Also, in each case, DeleteLocalRef is called on the JNIEnv_ pointer so the Java garbage collector knows it is free to deallocate the memory.

Additionally, we've verified the C++ code itself has no leaks by using the C language runtime function _CrtDumpMemoryLeaks().

In spite of all this we know from the ANTS Profiler that the C++ component is responsible for the vast majority of the memory leaks.

Consider the local objects in C++ code such as the jobjects and jstrings mentioned above.  If, for whatever reason, the Java garbage collector doesn't have time to dispose of these after the call to DeleteLocalRef and before control leaves the C++ function, could these objects masquerade as leaking C++ objects and therefore be reported by ANTS as part of the C++ component rather than part of the JVM?
Tagged:

Best Answers

Answers

  • Jessica RJessica R Posts: 1,319 Rose Gold 4
    Hi @concordia_1580,

    Thanks for your post!

    I unfortunately don't know much about how memory for Java is handled, but just to confirm, is the C++ component you mentioned a managed C++ component?

    Jessica Ramos | Product Support Engineer | Redgate Software

    Have you visited our Help Center?


  • concordia_1580concordia_1580 Posts: 4 New member
    Hi Jessica,
    Thanks for responding.  The C++ component is unmanaged and accessed from the .NET layer through interop.
  • Jessica RJessica R Posts: 1,319 Rose Gold 4

    Thanks @concordia_1580!

    You mentioned "In spite of all this we know from the ANTS Profiler that the C++ component is responsible for the vast majority of the memory leaks."

    Could you provide more detail on how ANTS confirmed this for you?

    Jessica Ramos | Product Support Engineer | Redgate Software

    Have you visited our Help Center?


  • concordia_1580concordia_1580 Posts: 4 New member
    Sure.  Attached is a screen shot of the unmanaged memory breakdown by module.  Our C++ component is named EZGeoInt.  Notice the JVM is only 5 MB but EZGeoInt is 522 MB.  So considering the information I provided in my original post, this result made me wonder if leaks associated with the Java native interface objects declared in EZGeoInt are being reported by ANTS as C++ leaks rather than JVM leaks. Thank you!
Sign In or Register to comment.