<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<p><font face="Georgia">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.</font><br>
</p>
<br>
<div class="moz-cite-prefix">On 3/27/18 6:33 AM, Nicolas Cellier
wrote:<br>
</div>
<blockquote type="cite"
cite="mid:CAKnRiT7z=kf7cVTfAmSP_n5C3D9M0XAKOhOsM=Lb0tTKxUr3zw@mail.gmail.com">
<div dir="ltr">
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>Hi Bob,<br>
</div>
<div>yes, you force me to rethink. The way
mark and sweep GC works, cycles in object
graphs do not matter.<br>
</div>
<div>As long as the objects in the cycles are
only pointed to weakly from roots, <br>
</div>
<br>
</div>
<div>| value weak array2 |<br>
</div>
value := Array new.<br>
</div>
weak := WeakArray with: value.<br>
</div>
3 timesRepeat: [Smalltalk garbageCollect].<br>
</div>
self assert: (weak count: #notNil) = 1. "Not yet
reclaimed, thisContext points to it thru value
variable"
<div>
<div>value := nil.<br>
</div>
3 timesRepeat: [Smalltalk garbageCollect].<br>
</div>
self assert: (weak count: #notNil) = 0. "This time, it
is reclaimed"
<br>
<br>
</div>
<div>"Example of cycle"<br>
</div>
<div>value := Array new: 1.<br>
</div>
<div>array2 := Array with: value.<br>
</div>
<div>
<div>
<div>value at: 1 put: array2.<br>
</div>
weak := WeakArray with: value.<br>
</div>
array2 := nil.<br>
</div>
<div>
<div>value := nil.<br>
</div>
3 timesRepeat: [Smalltalk garbageCollect].<br>
</div>
self assert: (weak count: #notNil) = 0. "The value is
reclaimed despite the cycle"
<br>
<br>
</div>
It's then VW that behaves strangely: I did not find any
pointer to the class nor its metaclass apart themselves<br>
</div>
(I took care to not add the metaclass to metaclass
superclass subclasses, because those are not weak).<br>
</div>
This has obscured my mind.<br>
</div>
Sorry for the noise.<br>
</div>
<div class="gmail_extra"><br>
<div class="gmail_quote">2018-03-26 23:15 GMT+02:00 Bob Arning <span
dir="ltr"><<a href="mailto:arning315@comcast.net"
target="_blank" moz-do-not-send="true">arning315@comcast.net</a>></span>:<br>
<blockquote class="gmail_quote" style="margin:0 0 0
.8ex;border-left:1px #ccc solid;padding-left:1ex">
<div text="#000000" bgcolor="#FFFFFF">
<p><font face="Georgia">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?</font><br>
</p>
<div>
<div class="h5"> <br>
<div class="m_-6117267556797383343moz-cite-prefix">On
3/26/18 3:07 PM, Nicolas Cellier wrote:<br>
</div>
<blockquote type="cite">
<div dir="ltr">
<div>
<div>
<div>
<div>
<div>
<div>
<div>Hi all,<br>
</div>
while porting MatFileReader to Squeak,
I encountered this questionable
behaviour:<br>
<br>
</div>
I create classes on the fly for holding
Matlab struct().<br>
</div>
I want those classes to be garbage
collected when no more used.<br>
<br>
</div>
If I store the classes in a WeakArray, then
this should normally not work:<br>
</div>
I mean that the classes should not be
reclaimed.<br>
</div>
Why?<br>
Because the metaclass points strongly to the
class (via thisClass variable).<br>
</div>
<div>And the metaclass can't be reclaimed either,
because it still has an instance.<br>
</div>
<div>That's what happens in Visualworks, classes
put in a WeakArray are never reclaimed.<br>
</div>
<div>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).<br>
<br>
</div>
<div>In Squeak, I used a WeakValueDictionary, and
to my surprise, discovered that the classes were
reclaimed.<br>
</div>
<div>Is this a bug?<br>
<br>
</div>
<div>Nicolas<br>
</div>
<div><br>
<br>
</div>
</div>
<br>
<fieldset
class="m_-6117267556797383343mimeAttachmentHeader"></fieldset>
<br>
</blockquote>
<br>
</div>
</div>
</div>
<br>
<br>
<br>
</blockquote>
</div>
<br>
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">
</pre>
</blockquote>
<br>
</body>
</html>