This is the mail archive of the guile@sources.redhat.com mailing list for the Guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Goops and finalizing


"Lars J. Aas" <larsa@sim.no> writes:

> Is there any way to have some sort of destructor for a goops class that
> kicks in before an instance is garbage collected?  I didn't see any doc
> on it...

weeeeell.

first, be aware that you don't get _any_ guarantee that any object
will ever die, much less die in a timely fashion.  you surely know
that, but just in case.

you have two choices when it comes to finalization:

* use guardians.  you can read up on them in the
  function-documentation for `make-guardian'.  this is a generic
  facility, not specific to GOOPS objects, and in general pretty neat
  and Schemey.

* replace the `free' procedure in the class vtable with something that
  both frees the memory and does something else.  this is a hack, can
  only be done in C, is a hack, requires you to read the code in
  struct.c, is a hack, the interface will surely change sometime
  "soon", and did I mention it's a hack?  there ;).

> (define-method finalize ((class <class>))
>   [finalize instance])

this is kinda impossible in a garbage-collected language, as it would
require calling Scheme code inside the GC.

-- 
Hit the philistines three times over the head with the Elisp reference manual.
                -- Michael A. Petonic

_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]