System.loadlibrary - Unload explicitly

469 views
Skip to first unread message

Ash

unread,
Oct 27, 2009, 1:02:09 AM10/27/09
to android-ndk
Hi!!

I am trying to find a way to explicitly unload the native library but
so far I couldn't findout any info on it. Is it possible to unload an
already loaded native library and reload it on need basis?

Can I load a native library in one process and use it in other process
without loading it? I would also like to understand, how the
references for loadlibraries are maintained, is it per VM/process or
per class?

Thanks in advance
Ash

fadden

unread,
Oct 27, 2009, 2:28:08 PM10/27/09
to android-ndk
On Oct 26, 10:02 pm, Ash <ashutoshkagra...@gmail.com> wrote:
> I am trying to find a way to explicitly unload the native library but
> so far I couldn't findout any info on it. Is it possible to unload an
> already loaded native library and reload it on need basis?

You can't. It's actually rather dangerous to do so. For example, if
you have some C++ code that created objects, and you unload the
library, your process will crash when the destructors attempt to run.

> Can I load a native library in one process and use it in other process
> without loading it? I would also like to understand, how the
> references for loadlibraries are maintained, is it per VM/process or
> per class?

On Linux, shared libraries are loaded per-process. Loading it in one
process does not enable it for use in others.

JNI adds an additional restriction that the same library cannot be
loaded by more than one class loader.
Reply all
Reply to author
Forward
0 new messages