How to unload dlls?

Hi! All,

I have an applet which copies 3 dlls from the server

to c drive of the client hard disk. I'm loading one dll by

calling the method System.load("..."). This loaded library

inturn loads other two libraries natively in C++ code(in

JNI_OnLoad function using the LoadLibrary).

In the stop method of applet I have called a native

method to unload the dlls which have been natively

loaded. I'm also able to delete the natively loaded dlls

from the c drive in the stop method after unloading them

natively. But I'm not able to unload the dll which has

been loaded by the method System.load(). Even after I

close the browser(IE), I'm seeing an instance of IE in the

process tab of Task manager dialog box.

Can anybody suggest me how I can unload the dll

loaded through System.load("..") method and also delete

it from the hard disk.

Any comments on this will be of a great help!!!

Thanx in advance

Pavana Chandrashekar

[1064 byte] By [pavanac] at [2007-9-26 2:45:41]
# 1
Write another dll that loads the first?Java doesn't allow you to unload dlls. You can either live with it or create your own JVM that does it.
jschell at 2007-6-29 10:27:49 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 2
Check out this other thread: http://forums.java.sun.com/thread.jsp?forum=4&thread=4941
swatdba at 2007-6-29 10:27:49 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 3
>Check out this other thread:Interesting. I looked at the code in that and can't find anything that suggests it is dealing with dlls in any special way. Anyone else see a difference?
jschell at 2007-6-29 10:27:49 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 4

Hi

I have the same problem too. In my case i cannot unload the dll using native method as the dll and the code that calls it will be a 3rd party stuff. I must be able to dynamically update the class and the dll..

here is my requirement

I want to be able to update a class that makes JNI calls dynamically .For this i have a custom classloader.The classloder successfully loads the native library the first time i run the class. On updating the class (i load a new instance of the classloader) i get the error message saying that the native library has already been loaded by another classloader instance. how can i unload the previous instance of the native library so that the update is successful..

Thanks in advance

sibi

sibijv at 2007-6-29 10:27:49 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 5

hello

In your case loading the library shouldn't be a problem at all since u're using a new instance of the class loader. if still u're getting this error then it means the old loader hasn't been garbage collected. make the old loader null and invoke the garbage collector.

System.gc();

System.runFinalization();

This should definitely work. Do make sure this is done before the native library is loaded by the new loader

annmary at 2007-6-29 10:27:49 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 6

> annmary said

>

> System.gc();

> System.runFinalization();

>

> This should definitely work. Do make sure this is

> done before the native library is loaded by the new loader.

No. It might work. There is nothing at all that you can do in java to force the garbage collector to run. You suggestion makes it more likely but does not guarantee it. You can write some JNI and call some of the internal stuff to force this, but obviously that is OS, JVM and version specific.

jschell at 2007-6-29 10:27:49 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 7
> System.gc();> System.runFinalization();> > This should definitely work. Do make sure this is done> before the native library is loaded by the new loaderThanks annmary . it worked for mesibi
sibijv at 2007-6-29 10:27:49 > top of Java-index,Java HotSpot Virtual Machine,Specifications...