With Camille we spent some minutes introducing a weak slot. A weak slot
with a weak reference i.e., it is not taken into account by the garbage
collector. If an object is only referenced by weak references it will be
garbage collected.

The nice thing about this is that now we can mix transparently weak and
non-weak slots inside the same object. For example:
Object subclass: #MyWeakThingy
    slots: { #weakLala => WeakSlot.
                #normalInstVar }
    classVariables: {  }
    category: 'SlotTestGuille'

weakLala: someLala
    weakLala:= someLala

weakLala
    ^ weakLala

weak := MyWeakThingy new.
o:= Object new.
weak weakLala. "=>Object new"
o :=nil.
weak weakLala. "=>nil"

We also implemented with Camille the #emit* methods to make it a bit
faster. A simple benchmark in my machine shows that

"With no optimizations"
[weak weakLala:o] bench  "14,338,031 per second"

"With optimizations"
[weak weakLala:o] bench "27,955,761 per second"

"A normal array access"
someArray := Array new: 1.
[someArray at: 1 put: o] bench  "'39,609,322 per second'"

We commited it into the inbox, the issue is the following:

https://pharo.fogbugz.com/f/cases/14998/Add-WeakSlot

Camille & Guille

Reply via email to