• Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem using ClassLoader  RSS feed

 
Fuad Abinader
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I'm having the following problem using my own ClassLoader.
Basically I need to dynamically load classes contained inside a JAR files, so I followed instructions for creating my own class loader. I did it, and after some problems, now I'm loading the classes through my own class loader.
The problem is that after releasing all references for my own class loader, it is still possible to load the classes from the JAR file even that the classloader in which the classes were resolved seems to be garbage-collected.
Does anybody know how to re-resolve a class? Or how to probide a solution to this problem?

Regards,

Fuad Abinader
 
Mr. C Lamont Gilbert
Ranch Hand
Posts: 1170
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i'd be surprised if the classloader was collected. it can't go untill all references to it are gone, all class objects of classes it loaded are gone, and of course all classes it loaded are gone.

I think you may even need a jvm switch to get classloaders to be collected because of the implications for static methods and data.
 
Edwin Dalorzo
Ranch Hand
Posts: 961
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe we could make sure that your ClassLoader is garbage collected. Extend your ClassLoader and override its finalize method. Write a message to the screen that says "I am about to be garbage collected". When you see that message on the console, then you must know, for sure, that your ClassLoader has been garbage collected.

After that, try to reload the classes. If your ClassLoader is gone and your Application ClassLoader do not have access to the jar file in its classpath, then it should throw an exception.

At least that's what I think.
[ May 17, 2006: Message edited by: Edwin Dalorzo ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!