<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">2018-03-27 13:02 GMT+02:00 Bob Arning <span dir="ltr"><<a href="mailto:arning315@comcast.net" target="_blank">arning315@comcast.net</a>></span>:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
  
    
  
  <div 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><div><div class="gmail-h5">
    <br></div></div></div></blockquote><div><br></div><div>Yes, the VM cannot rely on image side conventions and should follow the class (for example there are obsolete classes).<br>There is SpurMemoryManager>>markAndTraceClassOf: for that.<br></div><div><br><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div bgcolor="#FFFFFF"><div><div class="gmail-h5">
    <div class="gmail-m_3853484059178132440moz-cite-prefix">On 3/27/18 6:33 AM, Nicolas Cellier
      wrote:<br>
    </div>
    <blockquote type="cite">
      <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">arning315@comcast.net</a>></span>:<br>
          <blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
            <div 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="gmail-m_3853484059178132440h5"> <br>
                  <div class="gmail-m_3853484059178132440m_-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="gmail-m_3853484059178132440m_-6117267556797383343mimeAttachmentHeader"></fieldset>
                    <br>
                  </blockquote>
                  <br>
                </div>
              </div>
            </div>
            <br>
            <br>
            <br>
          </blockquote>
        </div>
        <br>
      </div>
      <br>
      <fieldset class="gmail-m_3853484059178132440mimeAttachmentHeader"></fieldset>
      <br>
      <pre></pre>
    </blockquote>
    <br>
  </div></div></div>

<br><br>
<br></blockquote></div><br></div></div>