Classes categories
Objects, Classes and Slots
Free-able objects
parametric class

Free-able objects [XL]

Starting with XL CLAIRE, a class can inherit from freeable_object that are special kind of ephemeral objects regarding the Garbage collector (GC). We can define two GC callbacks (prefree! and free!) for such object that will be called when the GC attempt to free an object giving a chance for such object to perform a cleanup operation :

As an illustration we could define the following long_double class that import from C++ the 'long double' data type :

 long_double* <: import()
 long_double <: freeable_object(value:long_double*)
 (c_interface(long_double*"long double*"))

 close(self:long_double: long_double ->
     (self.value := externC("(long double*)::malloc(sizeof(long double))"long_double*),
     self)

 free!(self:long_double: void -> externC("::free(self->value)")


categories Free-able objectsnormal dispatch [XL] Kernel interface

free! :: property(open = 3)

In a similar way to prefree! interface free! is called by the GC before a freeable_object is actually freed. It is a good place, for instance, to free externally allocated memory. An object x given to the free! handler should be handled with a lot of care :


categories Free-able objectsnormal dispatch [XL] Kernel interface

prefree! :: property(open = 3)

The prefree! interface is called by the GC before a freeable_object is actually freed. It give a chance to terminate inter-object operations that may need a last synchronization step (like the flush of a filter). Since an object x given to the handler prefree! is about to be freed you should never create reference on x in the scope of the handler (i.e. don't add x to a list, don't set a global var to x).