Class unloading doesn't work as described in this forum !!!

Hi,
to the problem of dynamic class unloading many people in this forum wrote:
- write your own class loader
- load the class to be unloaded later
- set all instances of your own class loader to null
- if the work is done set all instances of the loaded classes to null
- call the garbage collector and the classes will be removed
I constructed a simple test for the problem:
- the test class
public class Impl {
public String getVersion () {
return "1";
- instanciating the test class
- printing the value of getVersion() to the screen
- changing the return value of getVersion() and recompiling it (the test application is still runnig)
- unload try (see below)
- instanciating the test class
- printing the value of getVersion() to the screen
Back to the tipps above. Why doing this? The theory says a class loader stores every loaded class for
suppressing unnecessary reloads. In reality the classes are NOT stored in the own class loader but in
the parent of it. If no parameter is given to a class loader's constructor the parent of a class loader
is the system classloader.
Let's have a look at the source code of java.lang.ClassLoader.loadClass(...):
protected synchronized Class loadClass(String name, boolean resolve)
throws ClassNotFoundException
// First, check if the class has already been loaded
Class c = findLoadedClass(name);
if (c == null) {
try {
if (parent != null) {
### here the loadClass() of the parent is called and the
### loaded class is stored within the parent
c = parent.loadClass(name, false);
} else {
c = findBootstrapClass(name);
} catch (ClassNotFoundException e) {
// If still not found, then call findClass in order
// to find the class.
c = findClass(name);
if (resolve) {
resolveClass(c);
return c;
My Idea was: Give a null to the class loader's constructor so the classes cannot be stored within a parent.
Here my test class loader (it is build as it is described within javadoc of java.lang.ClassLoader
except the constructor):
import java.io.*;
public class MyClassLoader extends ClassLoader {
public MyClassLoader () {
super ( null );
public Class findClass ( String name ) {
byte[] b = loadClassData ( name );
return defineClass ( name, b, 0, b.length );
private byte[] loadClassData ( String name ) {
byte[] ret = null;
try {
InputStream in = new FileInputStream ( name + ".class" );
ret = new byte[in.available ()];
in.read ( ret );
} catch ( Exception e ) {
e.printStackTrace ();
return ret;
The loading of the class works fine
ClassLoader cl = new MyClassLoader ();
Class c = cl.loadClass ( "Impl" );
Object i = c.newInstance ();
Impl impl = (Impl)i;
The class "Impl" was found and instanciated. But the cast "Impl impl = (Impl)i;" causes a
"java.lang.ClassCastException: Impl"
May second idea was deleting all instances of the class to unload from the class loader via reflection.
A strange way I know but if this is the only way I will do it. But this doesn't work too.
After deleting the class from the class loader and all its parents the class is still anywhere in the depth
of the VM.
Can anybody help me with this problem?
Thanks in advance,
Axel.

<pre>
I made a similar and simpler program and it worked:
import java.net.URLClassLoader;
import java.net.URL;
public class DynamicExtension {
     public static void main(String args[]) throws Exception {
          URL[] ua = new URL[] {  new URL("file://c:\\TEMP\\") };
          URLClassLoader ucl = new URLClassLoader(ua);
          MyLoadable l =
               (MyLoadable) ucl.loadClass("LoadableObject").newInstance();
          l.printVersion();
          Thread.currentThread().sleep(10000);
//you have ten seconds to replace the old version of the LoadableObject.class file
//so yo?d better had compiled the new one before executing this
          ucl = new URLClassLoader(ua);
          l = (MyLoadable) ucl.loadClass("LoadableObject").newInstance();
          l.printVersion();
          ucl = null;
          l = null;
          System.gc();
public class LoadableObject implements MyLoadable {
     public void printVersion() {
          System.out.println("version 1");
     protected void finalize() {
          System.out.println("finalizing " + this);
public interface MyLoadable {     void printVersion();  }
C:\Java\TIJ2\Test>java DynamicExtension
version 1
version 2
finalizing LoadableObject@1bd03e
finalizing LoadableObject@4abc9
The ClassCastException was due to the fact that one class was loaded by the system class loader, the one that appers as Impl impl = (Impl), and the other by MyClassLoader. That mean that they are different for the VM because they are in different namespaces: The namespace for MyClassLoader is the set of classes loaded by itself and those returned to it by his parent class loader as a result of a request to MyClassLoader?s parent class loader to load a class.
Setting null for the parent of MyClassLoader was in fact the cause of the problem, because that caused a call to a native method called findBoostrapClass. I guess this method looks for the classes in the bootstrap classpath where MyClassLoader shouldn?t be. This causes MyClassLoader loaded the class itself. If MyClassLoader had had the system class loader as its parent the result had been that only one classloader would have loaded the class. This is what happens in the example above so no ClassCastException is thrown.
In the source code for ClassLoader
there is the following:
* The classes loaded by this class loader. The only purpose of this
* table is to keep the classes from being GC'ed until the loader
* is GC'ed.
private Vector classes = new Vector(); /*
and:
* Called by the VM to record every loaded class with this loader.
void addClass(Class c) {
classes.addElement(c);
I would like to have seen findLoadedClass checking the already loaded classes in this Vector, but this method is native. Anyway, as the code for loadClass shows, the parent or bootstrap classloader is checked if findLoadedClass doesn?t find the class; Can we guess that findLoadedClass only checks the clases loaded by the classloader, not its parent?
By the way, could an example like this be made in c++?
</pre>

Similar Messages

  • FF doesn't work anymore, and seeing this forum through IE6 makes me hate things

    == Issue
    ==
    Firefox is crashing or closing unexpectedly
    == Description
    ==
    This is a direct reply to http://support.mozilla.com/en-US/forum/1/594409 because I cannot answer to it. I selected "I have the same problem" among the checkboxes and it tells me "YOU MUST SPECIFY A POST SUBJECT". I tried all the checkboxes and the problem persists. I'm on IE6 because FF is out the window (read on) and to be honest, this entire domain loads ''poorly'' through here (no suprise, but guys, people come here to switch FROM 6.0, what are they going to do if they only see basic html unless they refresh twice per page?)
    Basically, the response:
    Exact same ''thing'' here. Today, suddenly and for no apparent reason FF and Opera crashed permanently at the same time. I could not start them, nor reinstall them, after reboot or in failsafe mode. Firefox installer v3.0.7 AND v3.6 both crash on 0% extracting process and die. I don't know what to do - my IE is a 6.0 version for design testing purposes - it doesn't even store cookies (and installing a newer IE just won't happen).
    <blockquote>edited by a moderator - eh
    https://support.mozilla.com/en-US/kb/Forum+and+chat+rules+and+guidelines</blockquote>
    == Firefox version
    ==
    3.0.7 and 3.6
    == Operating system
    ==
    Win XP SP3
    == Plugins installed
    ==
    Firebug (latest). Nothing else that didn't come with the box.

    WonderWoofy wrote:I think you may find relevant information here.  I ahve seem many of these threads in the forums lately.  Are you dual booting w/ another operating system... in particular, one that uses localtime for the hardware clock (and there is only one that does this).
    Thanks I'll look at that entry. Still I'd like to point out that this page clearly says that the timezone is to be set in rc.conf, which is a bit confusing. I must've followed this guide to get to my current configuration. I am dual booting with multiple other systems (xubuntu, win7, puppy, crunchbang) so from what I've read win7 might be the problem, but I haven't started it since i installed arch and my time has been off from the start.
    Should I simply use NTP now that pacman is working again?
    Thanks
    Last edited by miek (2012-09-03 17:41:56)

  • Capitalization doesn't work as described. One can start with lower case and change to upper, but changing from upper case to any of the other options doesn't work. Is there a way around this or is this just a glitch that needs fixing?

    In Pages capitalization doesn't work as described. One can start with lower case and change to upper, but changing from upper case to any of the other options doesn't work. Is there a way around this or is this just a glitch that needs fixing?

    I think it does work as described, but the description is not very complete. Capitalization does not change any of the characters that you type; what it does is allow some of the lower case characters to display as capitals. If you copy the result and paste it as plain text, you'll see that the lower case characters are still there. It doesn't actually say anywhere that it can make capitals display as lower case, and it can't.
    The obvious way around this is to actually type what you want.
    The more powerful way is to install WordService from Devon Technologies which adds the functionality of Pages' capitalization menu as well a lot of other ones. WordService actually changes the character to the one displayed, and it works in most of the applications on your Mac.

  • Hi , my sister got really mad and she banged her iPod touch 5th generation on a table and she banged it so hard that the screen didn't crack but inside the the iPod is damage as in like colors are popping out and the screen doesn't work, can i fixed this?

    Hi , my sister got really mad and she banged her iPod touch 5th generation on a table and she banged it so hard that the screen didn't crack but inside the the iPod is damage as in like colors are popping out and the screen doesn't work, can i fixed this?

    Apple will exchange your iPod for a refurbished one for this price. They do not fix yours.
    Apple - iPod Repair price      
    A third-party place like the following maybe less. Google for more.
    iPhone Repair, Service & Parts: iPod Touch, iPad, MacBook Pro Screens

  • Priority class command doesn't work with a certain program

    Hello folks,
    I'm trying to automatize the priority class setting of a program named FreeTrack through a command written in the shortcut. Hence in its "target" I've written this (I'm using Windows 7 x64):
    C:\Windows\System32\cmd.exe /c start /REALTIME /AFFINITY 8 "" "E:\Program Files (x86)\FreeTrack\FreeTrack.exe"
    As you can see I also wanted the affinity mask of the program to be set automatically upon launch, and it works fine. The issue is that the priority class remains unchanged to normal.
    I've tried removing the "affinity" command but it didn't work.
    The priority command does its job on another program (for the attempt I used Firefox).
    Is there any explanation for this anomalous behaviour? And, most importantly, is there a solution (which preferably doesn't involve installing additional programs) ?
    Thank you and regards

    All right, I've found a solution; I'll post it for anyone in need. It's not particularly elegant but still functional.
    First of all I've created a .cmd file in the folder where is located the executable of my interest.
    In it, using notepad, I've written as following:
    start /affinity 8 FreeTrack.exe
    ping 1.1.1.1 -n 1 -w 2000 > nul
    wmic process where name="FreeTrack.exe" CALL setpriority 256
    Note that the /affinity command is optional and not required (however, I needed it). Replace "FreeTrack.exe" with the name of your executable.
    The ping part pings a fake IP once and then waits 2000 milliseconds (set a higher waiting time if this one doesn't work).
    The third line changes the priority for all the processes under the name of "FreeTrack.exe" to, in my case, realtime.
    Priority legend:
    Low: 64 Below Normal: 16384 Normal: 32 Above Normal: 32768 High: 128 Realtime: 256
    Since the command prompt window appears for 2 seconds and I don't like that, I've created a .vbs file in the same folder of the .cmd file and executable. This hides the cmd window.
    I've put the following into the .vbs file (edited with notepad):
    Set WshShell = CreateObject("WScript.Shell" )
    WshShell.Run chr(34) & "FreeTrack.cmd" & Chr(34), 0
    Set WshShell = Nothing
    Replace "FreeTrack.cmd" with your .cmd file name.
    I've then created a shortcut on the desktop to the .vbs file and changed the icon to the one of the executable.
    Surely this solution won't work if the program keeps reverting back its priority while running.

  • How to restore a CD or .dmg to a disk? It doesn't work as described.

    To restore a .dmg file or the contents of a CD or DVD to a disk, I used to open Disk Utility, click on the .dmg file that I want to put on a disk, click the Restore tab, drag the .dmg to the source field and the disk to the Destination field.
    Now, on both my 10.6.1 MBP and on my wife's 10.4.11 MBP, dragging the CD icon from the desktop or finder window to the Destination field just won't take. If I try to drag the blank CD from the left column of DU, the whole window changes.
    The DU help menu says: "3. Drag the disk that will hold the contents of the disk image to the Destination field." That doesn't work for me.
    TIA for any ideas.
    Chris

    Works here. Create a new admin user account, log into it, and try there.

  • After installing Lion, my microsoft office suite doesn't work anymore, and show this message: Application Power PC no longer available. How can I resolve it?

    Is there any possibilty to recover the use of my Microsoft Office suite, which doesn't work anymore after installing Lion?
    The programs display this error message: "no puede abrir la aplicación Microsoft Excel (o any other) porque las aplicaciones Power PC ya no son compatibles"
    thanks for your help

    You will need to upgrade your suite of MS programs.
    Older suites, like MS Office 2004, use program versions written for Macs with PPC processors. In order to use those apps in pre-Lion OS's on an Intel-processor machine, it was necessary to install Rosetta, software designed just for the purpose of using PPC-apps on an Intel machine.
    Unfortunately, Lion does not support Rosetta, so those apps no longer work.
    Solution - update them to a version which will work in Lion, such as the MS Office 2008 suite, or newer if available.

  • Bug? Updating config profile doesn't work as described

    Apple's documentation implies that if you push a new profile to a phone that has the same "Identifier" as an already active profile, then the new profile will be recognized as a replacement to the existing one; if the Identifier is different, then the new profile will be applied in addition to any current ones.
    I recently made a change to a profile, without changing the ID, and sent it to my phone. The phone won't activate the profile, though. It gives an error message: "Can't install Profile: Only one Exchange account can be set up at a given time."
    This seems like a bug. If the Exchange settings in the new profile are identical to the old one, they should be kept; if different, they should be changed. If I want to modify any settings in the profiles that I've already pushed out to users, I'll have to make a new overlay profile; if I want to change the Exchange settings, I'll have to send them instructions on how to remove the existing profile before I can send the new one. Is there a workaround?

    You need to remove any profile that has Exchange keyed into it, then you can install the new profile for Exchange.
    Windows Mobile devices work this way, as well.
    We had about 50 people that we had to change profiles for and they were able to do the remove and install themselves (the new profiles were delivered from a public web site).
    I hope this helps.

  • Java Class.java doesn't work??

    I've compiled my java file with javac. But then when I type: java ClassName : for example it gives me exception in thread "main" java.lang.NoClassFoundDefError:
    I've already set the path, so I don't think that's the problem. Help please. Thanks in advance.

    I got the problem all the sudden - it was ok before. even after I reinstalled jdk1.3 as well as jdk1.4, I still got the same error message. I've gotten all the java_home, Path and Classpath setup (worked for a quite long time). I was testing JNDI when I noticed that problem - before that I was testing J2ee stuff and it seems works fine...
    any comment?
    (error: java.lang.noClassDefFoundError)
    thanks.

  • Restore Doesn't Work As Described

    I have an iPhone 4S. I use iCloud to sync the Reminders app to my Mac and iPad. I backup my iPhone 4S to my Mac - not to iCloud.  I accidentally deleted a lengthy Reminders *list* from the Reminders app this afternoon. Of course it immediately deleted itself from my Mac and iPad. So I immediately launched iTunes and restored my entire phone using "Restore from Backup" — an encrypted backup that I made well before accidentally deleting the list today.  But when I restored my phone, not only was that list I was hoping to restore NOT restored, but other lists were entirely missing. Not all my lists, just a few lists. The default (Reminders) list is there, as is a "Groceries" and "Market" list, but 2 other lists I'd created months ago are not restored.  What is the point of creating an encrypted backup of an iPhone if it does not restore all of the Apple-related apps and data?  How exactly are we supposed to backup the Apple-related apps and data to be able to restore things like Reminders lists, should they be deleted?  Any assistance is greatly appreciated. Thank you.

    Reminders is not part of the iTunes backup
    http://support.apple.com/kb/ht4946

  • I updated to firefox 9.0.1 and my yahoo mail doesn't work with firefox. This is a serious issue for me.

    A few days ago I updated to firefox 9.0.1, and when I am using firefox in the My Yahoo account, I can see my emails, but when I click on one to open it, I am asked to put in my password for yahoo. This shouldn't occur because it already know who I am because I can see my name there and my emails etc. When I put in my password it doesn't accept it.

    The location bar is also known as the address bar, it is where you enter web addresses.
    When it crashes does it submit any crash reports? If it does can you post some of the crash report IDs as that may help somebody identify the cause of the crashes. For details of how to get the crash report IDs see the [[Firefox crashes]] article.

  • My PC just updated and now my headphones jack doesn't work. Why is this?

    Everything was working fine until the update and I have no clue what updates were done. It was the mass that update when you go to close down the system.  I have a HP Pavilion dv6-3250us.

    Hi,
    Restore system to this point where you remember that everything was working without any problems.
    Resource:
    How to Do a System Restore in Windows 7
    ** Say thanks by clicking the "Thumb up" icon which is on the left. **
    ** Make it easier for other people to find solutions, by marking my answer with "Accept as Solution" if it solves your issue. **

  • In some downloads I get an error message as js doesn't work: a script on this page may be busy, or it may have stopped responding, script file is: file:///C:/Program%20Files/Mozilla%20Firefox/components/nsExtensionManager.js:623

    This is the entire message I get, but if click "stop" or "continue" nothing is fixed and the message is repeating forever...
    A script on this page may be busy, or it may have stopped responding. You can stop the script now, or you can continue to see if the script will complete.
    Script:
    file:///C:/Program%20Files/Mozilla%20Firefox/components/nsExtensionManager.js:623
    How this can be fixed
    regards
    Michey

    I encountered this issue with Win 7 but fixed it by doing the following: Open up AVG and then click on Tools / Advanced settings. On the bottom of the list should be AVG Security Toolbar, click on it. There should be an option to Repair the toolbar.

  • Do MBA displays really crack as easily as described in this forum?

    I have been contemplating the purchase of a MBA however the threads detailing cracking of the displays with "light" handling quite frankly scare me.  I would be purchasing to carry, I thought that's what it is made for.  Is this problem as widespread as the threads make it out to be.  Are there any users that have traveled with the MBA without the displays breaking?

    Anrando,
    Understand that the relative proclivity to breakage is difficult to ascertain in a forum like this for the simple reason that this is a support forum. Problems are the principle reason that a user would post a report of a broken screen, and is in no way representative of the overall satisfacton, or lack of problems of all other users.
    We've not seen very much in the way of follow-up to details in what may have illiicted screen damage. By and large, users are not reporting the frequency of screen breakages that could be ordinarily associated with normal use. Yes, to be sure, there are users who have broken screens that attest that their level of care was either ordinary, or care greater than ordinary, but nobody reports the details of the analysis of case geometries that might support a theory of defect.
    Bottom line is that there is no evidence that screen breakage is an issue for the vast majority of MBA users.

  • StateChangeEvent.WINDOW_MOVE doesn't work as it is described in CS SDK documentation

    var winGeom:WindowGeometry   = new WindowGeometry();
      winGeom.toplefx = 50;
      winGeom.toplefty = 50;
      CSXSInterface.getInstance().requestStateChange(StateChangeEvent.WINDOW_MOVE,   winGeom);
    This is an example from CS SDK documentation. I tried it in Photoshop CS5 - nothing happens. Am I alone, or it really doesn't work as described?

    In my experience most of the StateChangeEvents do not work. They are not fired or responded to...
    Harbs

Maybe you are looking for

  • Quicktime Streaming of keynotes does not work

    When I want to watch the keynotes on apple.com all I get is stuttering audio and chopped video. Why? How can I solve this? It's independent of the resolution I select. btw. why am I forced to use that stone-aged Quicktime to watch a movie by the "HTM

  • How do I purchace OS X Lion on a Mac that already has Lion?

    I bought a Mac Mini that came with OS X Lion on it. I would like to do a clean install, but I can't without the AppleID of the previous owner. I don't mind purchasing OS X Lion again, but the app store does not allow me to do that. How do I work arou

  • AirportAtheros.kext not installed properly when I re-install OSX

    Hi I recently bought a MacBookPro C2D and it was all working fine until all of a sudden it no longer opened .dmg files. after a while i rebooted and it wouldn't restart. so after a stress i reinstsalled OSX... that fixed the .dmg problem but now when

  • Issue in adapters mapping in OIM 11g

    Hi, I am having the issue in adapters mapping in OIM 11g..... I had created an Entity Adapter using utility task in OIM... and I had attached it to post update of users form in data object manager.... But when I am trying to map the adapter variables

  • Photo Booth slows down!

    I have a MBP 2.0 with 10.4.6 and I've noticed that Photo Booth runs very slowly when I chose effects button #1 (so you can see all the effects at the same time)... When I go to the second page of effects or just operate with one effect at a time, it