![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
A few methods in Object support the creation of particular objects. This include:
mourn
message to the object.
mourn
when the first instance variable is not referenced
or is referenced only through another instance variable in the
ephemeron.
Ephemerons provide a very versatile base on which complex interactions with the garbage collector can be programmed (for example, finalization which is described below is implemented with ephemerons).
finalize
method is called. Before finalize
is called,
the VM implicitly removes the objects from the list of finalizable
ones. If necessary, the finalize
method can mark again
the object as finalizable, but by default finalization will only occur
once.
Note that a finalizable object is kept in memory even when it has no references, because tricky finalizers might "resuscitate" the object; automatic marking of the object as not to be finalized has the nice side effect that the VM can simply delay the releasing of the memory associated to the object, instead of being forced to waste memory even after finalization happens.
An object must be explicitly marked as to be finalized every time the
image is loaded; that is, finalizability is not preserved by an
image save. This was done because in most cases finalization is
used together with CObject
s that would be stale when the image is
loaded again, causing a segmentation violation as soon as they are accessed
by the finalization method.
become:
, basicAt:put:
,
and possibly at:put:
too (depending on the implementation of the
method).
Note that GNU Smalltalk won't try to intercept assignments to fixed
instance variables, nor assignments via instVarAt:put:
. Many
objects (Characters, nil
, true
, false
, method
literals) are read-only by default.
aBoolean
.
#basicNew
, but the object won't move across garbage
collections.
#basicNew:
, but the object won't move across garbage
collections.
#new
or #new:
to create an object
Note that, although particular applications will indeed have a need for
fixed, read-only or finalizable objects, the #makeWeak
primitive
is seldom needed and weak objects are normally used only indirectly,
through the so called weak collections. These are easier to use
because they provide additional functionality (for example, WeakArray
is able to determine whether an item has been garbage collected, and
WeakSet
implements hash table functionality); they are:
WeakArray
WeakSet
WeakKeyDictionary
WeakValueLookupTable
WeakIdentitySet
WeakKeyIdentityDictionary
WeakValueIdentityDictionary
Versions of GNU Smalltalk preceding 2.1 included a WeakKeyLookupTable
class
which has been replaced by WeakKeyDictionary
; the usage is completely
identical, but the implementation was changed to use a more efficient
approach based on ephemeron objects.
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |