According to this and this, it seems that a dll is only unloaded when the reference to the ClassLoader object is gone and the garbage collector runs. If this is the case, can you simply load the dll in a thread, and then kill the thread to achieve the same effect without having to create a custom ClassLoader? Something like this:
new Thread(
new Runnable()
{
public void run()
{
System.load("dll");
}
}
).start(); //Will load the dll, then there will be no references to the thread
System.gc(); //Will unload the dll
I would probably do something more elaborate than this in a real life setting, but just to show the point.