[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Destructors & CLOS?

On Sun Jul 11 19:02:10, Scott Storkel writes about problems trying to
reproduce the destructor functions of C++ in CLOS:

> Both the connection objects and context area objects contain
> macptrs that reference non-relocatable data in the Mac heap.
> Is there any way to insure that when an application that uses my
> library quits all context areas are freed properly and all connections
> closed gracefully?

The manual for MCL2 cautions:
  If your program maintains ppointers to the Madcintosh heap, you
  should deallocate these with a function included on the list
  *save-exit-functions*. You can then reinitialize the pointers and
  handles with a function you pplace on the list *restore-lisp-functions*
The same section tells you to dispose of all Mac  handles and pointers 
before doing a save-application.

Notice that this also addresses the work around you mention:
  Is there any way to run through the list an
  close all the connections before an application exits? Something like
  the on_exit() or atexit() functions provided in C?
Just ensure that you add a function to *save-exit-functions* to go through
the list and do the cleanup. 

Since the predefined function (supplied with the MCL2 system) should be
called last, add your functions to the front:
  (setq *save-exit-functions* (push #'my-cleanup-function *save-exit-functions*))
   you can also use pushnew    using the function-name as a test for equality.