I load a shared library, with the classic System.loadLibrary() method, from a static java block. The library has global object allocated statically:
class Foo
{
public:
Foo()
{
}
~Foo()
{
logtofile( "Foo::~Foo() called" );
}
}
Foo dummy;
The global function logtofile writes a log file on the sdcard. While the constructor gets called when the library is loaded, it seems to me that the destructor is never called. I expected that between two constructors calls there should be a destructor call. So the question is: when the Foo destructor gets called?
Android never unloads native libraries; usually the app process dies spontaneously when the system decides that it needs its resources - and it does an equivalent of kill -9
, never calling destructors or Java finalize()
.