[cffi-devel] A question about memory management and garbage collection
Luís Oliveira
luismbo at gmail.com
Sun May 8 22:16:44 UTC 2011
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,
--
Luís Oliveira
http://r42.eu/~luis/
More information about the cffi-devel
mailing list