Would Java Native Interface objects instantiated in C++ appear in the ANTS Profiler as C++ leaks
concordia_1580
Posts: 4 New member
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?
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
-
Jessica R Posts: 1,319 Rose Gold 4Thank you!
The unmanaged memory breakdown should be accurate, so going back to the original question:"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?" - It depends on how the memory is allocated by either jvm or EZGeoInt as that could indeed cause the reported memory to be a part of one or the other module but we unfortunately don't know enough to say for sure .
AMP has limited capabilities of finding memory leaks in unmanaged modules so tracking down such leaks may be significantly harder than for regular managed objects. If it's any help though, we advise following the documentation for analyzing unmanaged memory problems, keeping in mind that AMP is only able to point in the general direction of where the unmanaged memory may be leaking:
https://documentation.red-gate.com/amp10/strategies-for-memory-profiling/checking-unmanaged-memory-usage
https://documentation.red-gate.com/amp10/working-with-profiling-results/the-summary-page#Thesummarypage-Unmanagedmemorybreakdownbymodule
https://documentation.red-gate.com/amp10/understanding-memory-problems/memory-management-primer#Memorymanagementprimer-Unmanagedmemoryleaks
-
concordia_1580 Posts: 4 New memberSounds good, Jessica. Thank you for responding and for the web links. I'll check them out
Answers
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?
Thanks for responding. The C++ component is unmanaged and accessed from the .NET layer through interop.
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?