[Ecls-list] Automatic memory reclamation

Matthew Mondor mm_lists at pulsar-zone.net
Thu Dec 13 23:31:13 UTC 2012


On Thu, 13 Dec 2012 19:50:01 +0100
Peter Enerccio <enerccio at gmail.com> wrote:

> Is it possible for automatic memory reclamation when object is no longer
> needed (ie it's parent foreign type has been disposed in the ecl memory)?
> 
> Or the same equivalent for defclass made class instance.
> 
> The reason being, in sdl, you must call SDL_FreeSurface when it's no longer
> needed and it would be appropriate to call it when object holding the
> reference to it (or class holding the reference to the object) is being
> disposed by the system.

I agree with all that juanjo said;

Note also that it's common in lisp to use WITH- macros making use of
UNWIND-PROTECT, such that code can easily ensure that an object be
closed or freed when no longer needed.  This could be faster than using
finalizer functions when it's possible.

At
http://cvs.pulsar-zone.net/cgi-bin/cvsweb.cgi/~checkout~/mmondor/mmsoftware/cl/test/mmffi-sdl.lisp?content-type=text%2Fplain
you'll see a few examples of such macros: WITH-SDL-SURFACE (to ensure
that we free the surface), WITH-SDL-LOCK (to ensure that unlocking be
done).

Because of garbage collection, objects which only consist of memory and
have no associated OS resources (such as non-video surfaces) may not
need any special treatment, unless they're considered too large and
increasing the heap is not wanted (and the heap fills too fast causing
frequent gc runs increasing latency).
-- 
Matt




More information about the ecl-devel mailing list