[cffi-devel] A question about memory management and garbage collection

nitralime nitralime at googlemail.com
Mon May 9 09:14:14 UTC 2011


Thanks a lot for your feedback!

I have also intended to try finalization using a closure!
But I wasn't that sure if it is an "idomatic" way to do that
or there maybe an even more clever way for accomplishing it.


By further googling yesterday I have also found similar
code fragments at

/http://code.google.com/p/lispbuilder/source/browse/trunk/lispbuilder-sdl/sdl/cffi-finalizers.lisp?r=426/

I'm just wondering about "cffi:finalize" which I couldn't
find in my own installation of cffi package!

Am I missing something?

Regards
Nik



On 05/09/2011 12:16 AM, Luís Oliveira wrote:
> On Sun, May 8, 2011 at 1:39 PM, Nitralime<nitralime at googlemail.com>  wrote:
>> What would be a correct solution to avoid memory leaks in this situation?
>> Using a finalizer seems to be a possible way to go. But I'm not sure how
>> this can be done by just using the finalizer parameters "object" and
>> "function"
>> where "function" can't reliablely access "object" (cf. documentation of
>> finalizer
>> in "trivial-garbage"  package)!!
> Here's some pseudo-code to achieve what you're looking for:
>
>    (let ((ptr (grab-your-table-pointer)))
>      (tg:finalize your-wrapper-object
>                   (lambda ()
>                     (table-free ptr))))
>
>
> HTH,
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.common-lisp.net/pipermail/cffi-devel/attachments/20110509/dc3a1082/attachment.html>


More information about the cffi-devel mailing list