-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Greetings,
I believe the answer to this question is "yes", at least under Win32. In
Win32, your JNI code is contained in a DLL. In a Win32 DLL, there is a
magic entry point which is automatically invoked by the operating system
immediately after the DLL loads and immediately before it unloads
(INCLUDING if the process is terminated with ExitProcess(), as it would
be even if the main program was written in assembly - but NOT if by
TerminateProcess(), which hardly anyone does anyway). The Visual C++
runtime provides its own definition of this function which initializes
and destroys global (and presumably static) objects. I have tested this
functionality personally: when a DLL containing a global object is
loaded with LoadLibrary(), the global object's constructor runs. When
FreeLibrary() unloads the library, the destructor runs. It doesn't
matter what language or what program loads and unloads the DLL: the
invocation of the load/unload callback (often referred to as DllMain)
occurs as a function of the operating system, and the CRT associated
with the DLL provides the entry point which initializes and destroys
globals.
I think Linux also provides a similar pair of magic functions in .SO files.
Chris
If I'm writing some native code using the C++ JNI API and my
C++ code has a static object with a destructor, is it
guaranteed that said destructor will be called before the
process terminates (as it would be if this were plain C++)?
I would think the answer would be "yes" since this is outside
the purview of the JVM.
- Paul
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (MingW32)
Comment: GnuPT 2.7.2
Comment: Using GnuPG with Thunderbird -
http://enigmail.mozdev.org
iD8DBQFDTfMi6ZGQ8LKA8nwRAgrjAKCVhV3hMrYq8OCT8dc2xaNW4iEVAQCeIRm5
9fmpBjG+hHfs5a02ToziKpQ=
=n6s7
-----END PGP SIGNATURE-----