Hi all, while porting MatFileReader to Squeak, I encountered this questionable behaviour:Because the metaclass points strongly to the class (via thisClass variable). And the metaclass can't be reclaimed either, because it still has an instance. That's what happens in Visualworks, classes put in a WeakArray are never reclaimed. Fortunately, there is some Ephemeron support in VW to work around this (such loop are detected by ephemerons, and strong references by some object ephemerely pointed to does not count). In Squeak, I used a WeakValueDictionary, and to my surprise, discovered that the classes were reclaimed. Is this a bug? Nicolas |
Other that the WeakValueDictionary, is there
anything referencing either the class or metaclass? If not, then
they would be collected. Perhaps VW is saving a reference
elsewhere? On 3/26/18 3:07 PM, Nicolas Cellier
wrote:
|
> On 26-03-2018, at 2:15 PM, Bob Arning <[hidden email]> wrote: > > Other that the WeakValueDictionary, is there anything referencing either the class or metaclass? If not, then they would be collected. Perhaps VW is saving a reference elsewhere? Usually a class' superclass would point to it with the subclasses array. If you were to make classes and *not* install them as a child of some superclass then I'd anticipate the class getting collected as soon as there are not instances being held onto. You could probably do interesting things by having the subclass array be weak and maybe having a mechanism that can (re)load a class when actually needed. But wait! That's at least in part what Craig has been doing with Context for some time now. tim -- tim Rowledge; [hidden email]; http://www.rowledge.org/tim Useful Latin Phrases:- Quo signo nata es? = What's your sign? |
In reply to this post by Bob Arning-2
Hi Bob, yes, you force me to rethink. The way mark and sweep GC works, cycles in object graphs do not matter. As long as the objects in the cycles are only pointed to weakly from roots, | value weak array2 | value := Array new.value := nil. 3 timesRepeat: [Smalltalk garbageCollect]."Example of cycle" value := Array new: 1. array2 := Array with: value. value at: 1 put: array2. weak := WeakArray with: value.value := nil. 3 timesRepeat: [Smalltalk garbageCollect].2018-03-26 23:15 GMT+02:00 Bob Arning <[hidden email]>:
|
In reply to this post by timrowledge
Hi Tim, yes, MatFileStructureElement class has an instance variable named weakSubclasses which is a WeakValueDictionary for that purpose.2018-03-26 23:25 GMT+02:00 tim Rowledge <[hidden email]>:
|
In reply to this post by Nicolas Cellier
I don't *know*, but it does seem possible
that a garbage collector could follow the class field of every
marked object and mark those classes as well. Maybe VW does
that? Not necessary, of course, in ordinary Smalltalk as classes
are generally strongly held by the eponymous root. On 3/27/18 6:33 AM, Nicolas Cellier
wrote:
|
2018-03-27 13:02 GMT+02:00 Bob Arning <[hidden email]>:
Yes, the VM cannot rely on image side conventions and should follow the class (for example there are obsolete classes). There is SpurMemoryManager>>markAndTraceClassOf: for that.
|
In reply to this post by Bob Arning-2
> On 27-03-2018, at 4:02 AM, Bob Arning <[hidden email]> wrote: > strongly held by the eponymous root. That's my next techno-death-metal-punk band name... tim -- tim Rowledge; [hidden email]; http://www.rowledge.org/tim Never do at compile-time what you can put off till run-time |
In reply to this post by Nicolas Cellier
HI Nicolas,
On Tue, Mar 27, 2018 at 3:33 AM, Nicolas Cellier <[hidden email]> wrote:
Is there difference between 32-bit and 64-bit VisualWorks? Like Spur, 64-bit VW uses a class table, whereas 32-bit VW has class pointers in object headers. So if you see the behavior in one but not the other that could point to a bug in tracing the class table (and its likely my bug).
_,,,^..^,,,_ best, Eliot |
Hi Eliot, Let me check...2018-03-27 21:14 GMT+02:00 Eliot Miranda <[hidden email]>:
|
Both vw7.8 32bits and vw8.3 64bits return 1 to this test: | superStruct meta struct weak | superStruct := Object. meta := Metaclass new. meta hash. meta setSuperclass: superStruct class. meta methodDictionary: MethodDictionary new. meta setInstanceFormat: (Behavior formatFromType: #none super: superStruct class instVars: Array new). struct := meta new. struct hash. struct setSuperclass: superStruct. struct methodDictionary: MethodDictionary new. struct setInstanceFormat: (Behavior formatFromType: #none super: superStruct instVars: Array new). struct instanceVariables: Array new. struct setName: 'TestStickyWeak'. weak := WeakArray with: struct. meta := struct := nil. "break references" 3 timesRepeat: [ObjectMemory garbageCollect]. weak count: #notNil. 2018-03-27 21:20 GMT+02:00 Nicolas Cellier <[hidden email]>:
|
Err, my bad... In VW, reclaimed objects are not replaced by nil but by 0 (zero). The example correctly answer 0 if I replace ^weak count: [:e | e ~= 0]. Cross dialect is a path full of pitfalls 2018-03-27 21:41 GMT+02:00 Nicolas Cellier <[hidden email]>:
|
Free forum by Nabble | Edit this page |