[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: gc and deallocation
- To: e@flavors.com (Doug Currie, Flavors Technology, Inc.), tar@isi.edu, info-mcl@ministry.cambridge.apple.com
- Subject: Re: gc and deallocation
- From: bill@cambridge.apple.com (Bill St. Clair)
- Date: Wed, 5 Jan 1994 15:09:24 -0600
At 2:58 PM 1/5/94 -0500, Doug Currie, Flavors Technology, Inc. wrote:
>At 10:15 AM 94.01.05 -0500, Thomas A. Russ wrote:
>>In article <...> bill@cambridge.apple.com (Bill St. Clair) writes:
>> > At 10:40 PM 1/4/94 -0500, Robert Bruce Findler wrote:
>> >>What happens to memory that is allocated in a clos object when the
>> >>object is gc'ed? Is there a method that should be defined to clean-up
>> >>after the object? Some sort of deallocate-instance?
>> >
>> > When a CLOS object is garbage collected, it's memory is freed for reuse.
>> > The memory of the objects in its slots will also be freed if those objects
>> > are not referenced by any other live objects. MCL's garbage collector
>> > does not support an explicit user-specifiable clean-up procedure.
>> > You normally don't need one, though some applications, e.g. persistent
>> > object databases, can benefit from such a feature.
>> >
>>
>>I would imagine that if you have pointers into the Macintosh heap that
>>were stored in the CLOS object you would end up with a memory leak if
>>you didn't have some disposal routine of your own. If you do this, then
>>you will need to explicitly deallocate the Macintosh heap memory.
>
>In our OODB we have used a MCL feature...
>
>(eval-when (:compile-toplevel :execute)
> (require "LAPMACROS"))
>
>(defun new-gcable-handle (size)
> (let ((h (#_newhandle size)))
> (when (%null-ptr-p h)
> (gc)
> (setq h (#_newhandle size)))
> (if (%null-ptr-p h)
> h
> (%setf-macptr (ccl::make-gcable-macptr ccl::$flags_DisposHandle) h))))
>
>Handles created by new-gcable-handle in the Mac heap are gc'd just like
>LISP heap objects.
>
>I assume, since it's undocumented, that Apple does not sanction this for
>general use or imply future support [Bill?].
That is strictly true. Since MCL uses gcable macptr's internally, however,
I doubt that support for them will disappear any time soon.
BTW, you don't need to require "LAPMACROS" to make the above code
work, (require "LISPEQU") is sufficient. Here's some documentation
I sent out a while back:
---------------------------------------------------------------------
Message-Id: <9210212208.AA28917@cambridge.apple.com>
Date: Wed, 21 Oct 1992 18:08:58 -0500
To: r0ml@is.morgan.com (The R0ML)
From: bill@cambridge.apple.com (Bill St. Clair)
Subject: Re: clos destructors
Cc: bill
>|> It DOES have an undocumented non-general
>|> finalization for MACPTRs. If a MACPTR is created in a special way,
>|> the garbage collector will call one of #_DisposePtr, #_DisposeHandle,
>|> #_DisposeWindow, or #_DisposeGWorld on it before collecting its space.
>|> I'll provide documentation for this feature if anyone is interested,
>
>Yes, very much interested. Would you mind e-mailing the documentation?
Here's some code I wrote and sent out earlier today. If you need
GCable windows or GWorlds, use $flags_DisposWindow or $flags_DisposGWorld.
---------------------------------------------------------------------------
; gcable-macptrs.lisp
;
; How to make a pointer or handle that will be disposed of
; by the GC when it is no longer reachable.
(in-package :ccl)
(export '(make-gcable-handle make-gcable-pointer))
(eval-when (:compile-toplevel :execute)
(require "LISPEQU") ; $flags_DisposXXX
)
(defun make-gcable-handle (size-or-handle)
(let ((ptr (ccl::make-gcable-macptr ccl::$flags_DisposHandle)))
(if (fixnump size-or-handle)
(%setf-macptr ptr (#_NewHandle :errchk size-or-handle))
(progn
(unless (handlep size-or-handle)
(error "~s is not a fixnum or handle." size-or-handle))
(%setf-macptr ptr size-or-handle)))
ptr))
(defun make-gcable-pointer (size-or-pointer)
(let ((ptr (ccl::make-gcable-macptr ccl::$flags_DisposPtr)))
(if (fixnump size-or-pointer)
(%setf-macptr ptr (#_NewPtr :errchk size-or-pointer))
(progn
(unless (zone-pointerp size-or-pointer)
(error "~s is not a fixnum or zone pointer." size-or-pointer))
(%setf-macptr ptr size-or-pointer)))
ptr))