[Pharo-project] Why do I need a #removeAllObsoleteSubclasses in to garbage collect?
Hi guys. I have a simple scenario where I create classes and then I remove them. I just want to be sure the amount of metaclasses and Class subclasses is correct. Hence, I have the following test. What I don't understand is that the test only works when I do a #removeAllObsoleteSubclasses to all classes. Soâ¦my questions is, is that correct? I am doing something wrong? because I would expect that #removeFromSystem takes care about that⦠this means that there will be obsolete classes/metaclasses hanging around until I send #removeAllObsoleteSubclasses ? Even moreâ¦the values in WeakKeyToCollectionDictionary (the class of the class var ObsoleteSubclasses in Behavior) are WeakArray⦠so they shouldn't be bothering. Sometimes the test is yellowâ¦a wait a little bit and then if I run it is greed again. When it fails, it is always the same, metaclassesBeforeTest has 1 less inst than Metaclass instanceCount. Sometimes it is the other way around and it has 1 more instead of one less. Thanks a lot for any clue⦠testXXX "Tests materialization of a hierarchy of classes that are not defined in the image and classes that indeed are defined. In addition we test to correctly create the necessary amount of classes and metaclasses." | classes a b c d metaclassesBeforeTest classSubclassesBeforeTest | 3 timesRepeat: [Smalltalk garbageCollect]. metaclassesBeforeTest := Metaclass instanceCount. classSubclassesBeforeTest := Class allSubclasses size. a := Object subclass: #Xaaa instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: ''. b := a subclass: #Xbbb instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: ''. c := a subclass: #Xccc instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: ''. d := Date subclass: #Xddd instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: ''. classes := Array with: a with: b with: c with: d. classes do: [ :aClassOrTrait | aClassOrTrait removeFromSystem ]. classes := nil. a := b := c := d := nil. 6 timesRepeat: [Smalltalk garbageCollect]. Smalltalk allClasses do: [:each | each removeAllObsoleteSubclasses]. self assert: metaclassesBeforeTest = Metaclass instanceCount . self assert: classSubclassesBeforeTest = Class allSubclasses size. -- Mariano http://marianopeck.wordpress.com
participants (1)
-
Mariano Martinez Peck