terry@cs.tamu.edu (Terry Escamilla) (02/05/91)
Hello. I ran into a few problems with ST v/286 while working at home last night. (1) How do you get rid of Global Variables? I created a global var as an instance of a class. When I tried to modify the class, ST claimed I couldn't because my class had instances. I tried a series of mistakes as indicated below. (2) First I tried 'Smalltalk at: #VarName put: nil'. But that didn't solve the problem. I think it removed the relationship link from VarName to the class, but not vice versa. So my class still thought it had some instances. (3) Then I tried 'Smalltalk removeKey: #VarName' which screwed up everything. I had to reload the system and fileIn all of the classes I had written. (4) By accident, I removed the name of one of my subclasses from the Smalltalk system dictionary. However, in the ClassBrowser, the parent class still was linked to that subclass. Clicking on the subclass name in the ClassBrowser resulted in an error message telling me that the subclass did not exist (even though it shows in the Browser list for the parent class). So, there's no way to stop the subclass from showing up in the Browser. Any way to fix this? I've decided to avoid global variables all together because I could never figure out a way to disassociate a global variable from the class it was created from. Here are a few other questions. (5) Is there any way to find out the names of all the global variables the system knows? I apparently forgot some (and had already compressed the change log), so it was impossible for me to remove them because I didn't know their names. (6) Back to (1) above, even if you know the name of a global var, how do you delete it? (7) Is there any way to delete the instances which a class has? I tried a bunch of different ways to inspect the class, but could never get a useful list of current instances for that class. If I'd found the instances list and modified it, would that have caused some dangling pointers anywhere? (8) If there are some instances of a class, and you want to change the class, the instances must somehow be deallocated. If they are global variables, is there a way to de-reference them from the class without removing them from the system dictionary? Thanks for any insight on this murky matter. Terry Escamilla terry@cs.tamu.edu
MUHRTH@tubvm.cs.tu-berlin.de (Thomas Muhr) (02/09/91)
In article <11770@helios.TAMU.EDU>, terry@cs.tamu.edu (Terry Escamilla) says: > >Hello. I ran into a few problems with ST v/286 while working >at home last night. > >(1) How do you get rid of Global Variables? I created a > global var as an instance of a class. When I tried > to modify the class, ST claimed I couldn't because my > class had instances. I tried a series of mistakes > as indicated below. > >(2) First I tried 'Smalltalk at: #VarName put: nil'. > But that didn't solve the problem. I think it > removed the relationship link from VarName to the > class, but not vice versa. So my class still thought > it had some instances. > >(3) Then I tried 'Smalltalk removeKey: #VarName' which > screwed up everything. I had to reload the system > and fileIn all of the classes I had written. > >(4) By accident, I removed the name of one of my subclasses > from the Smalltalk system dictionary. However, in > the ClassBrowser, the parent class still was linked to > that subclass. Clicking on the subclass name in the > ClassBrowser resulted in an error message telling me > that the subclass did not exist (even though it shows > in the Browser list for the parent class). So, there's > no way to stop the subclass from showing up in the > Browser. Any way to fix this? > >I've decided to avoid global variables all together because I >could never figure out a way to disassociate a global variable >from the class it was created from. Here are a few other >questions. > >(5) Is there any way to find out the names of all the global > variables the system knows? I apparently forgot > some (and had already compressed the change log), so it > was impossible for me to remove them because I didn't > know their names. > >(6) Back to (1) above, even if you know the name of a global > var, how do you delete it? Open an Inspector on the global vars dictionary: Smalltalk inspect You can then easily remove global vars but careful, you already made the experience: Do not remove vars which cannot be cleanly removed this way (class templates) To remove a class completely which you accidently removed by the above method, there is a method, but I cant remember now. >(7) Is there any way to delete the instances which a class > has? I tried a bunch of different ways to inspect the > class, but could never get a useful list of current > instances for that class. If I'd found the instances > list and modified it, would that have caused some > dangling pointers anywhere? Try. CLASSXY allInstances inspect >(8) If there are some instances of a class, and you want to > change the class, the instances must somehow be deallocated. > If they are global variables, is there a way to > de-reference them from the class without removing them from > the system dictionary? You should trace the instances and remove every "handle". Then, the garbage collector will take it away next time he runs. Try CLASSYX allInstances first allReferences inspect, then use the same method sequence for every reference - this can be quite a long work! The ReferenceTracer from the last Scoop (you should have gotten it as a DigiTalk customer ?) is a much better idea. I dont want to tell you the dirty method, because this can get you in much trouble sometimes.... Take alook at class vars also, they sometimes are theb references you are looking for. - Thomas