Lisp HUG Maillist Archive

CLOS object finalization

Dear everyone,

I am encapsulating foreign allocated objects within CLOS classes.  
In  my case, it is okay to free the memory when the garbage collector 
reclaims the objects.  So here is how I am finalizing my CLOS objects:


(defgeneric finalize-object (object)
  (:method (object)
    (declare (ignore object))
    nil))

(hcl:add-special-free-action 'finalize-object)


(defclass my-class ()
  ())

(defmethod initialize-instance :after ((self my-class) &key)
  (hcl:flag-special-free-action self))

(defmethod finalize-object ((self my-class))
  ;; Do whatever is needed to finalize the object here ...
  ;; Warning: the thread in which this code is called is unknown.
  ...)


FLI users: and you, how do you do this?
Do you have a different technique?
Are there any pitfalls I have missed?

I  search  for  something  already existing in LW, but I did not find 
anything  similar.  I thought the problem wasn't so specific ...


Cheers,
Camille


Re: CLOS object finalization

Hi Camille,

The RDNZL code also includes examples of this technique - pretty
similar to what you are doing.

Cheers,
Edi.


On Wed, Jan 4, 2012 at 6:14 PM, Camille Troillard <camille@osculator.net> wrote:
>
> Dear everyone,
>
> I am encapsulating foreign allocated objects within CLOS classes.
> In  my case, it is okay to free the memory when the garbage collector
> reclaims the objects.  So here is how I am finalizing my CLOS objects:
>
>
> (defgeneric finalize-object (object)
>  (:method (object)
>    (declare (ignore object))
>    nil))
>
> (hcl:add-special-free-action 'finalize-object)
>
>
> (defclass my-class ()
>  ())
>
> (defmethod initialize-instance :after ((self my-class) &key)
>  (hcl:flag-special-free-action self))
>
> (defmethod finalize-object ((self my-class))
>  ;; Do whatever is needed to finalize the object here ...
>  ;; Warning: the thread in which this code is called is unknown.
>  ...)
>
>
> FLI users: and you, how do you do this?
> Do you have a different technique?
> Are there any pitfalls I have missed?
>
> I  search  for  something  already existing in LW, but I did not find
> anything  similar.  I thought the problem wasn't so specific ...
>
>
> Cheers,
> Camille
>


Re: CLOS object finalization

Unable to parse email body. Email id is 11435

Updated at: 2020-12-10 08:37 UTC