<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
</head>
<body bgcolor="#ffffff" text="#000000">
<font face="Optima">Hi folks!<br>
<br>
I have the follwoing situation:<br>
<br>
A foreign function call returns a pointer to a "table" object. <br>
This is an opaque object that can only be manipulated by <br>
the APIs provided by the foreign library. To avoid memory leaks <br>
the "table" objects should by destroyed by a call to
"destroy_table" <br>
function if they are not used anymore.<br>
<br>
I have wrapped the "table" object and its corresponding API
functions <br>
in a CLOS object with appropriate methods. Instances of this CLOS
object <br>
will be returned by function calls on the Lisp side.<br>
<br>
The CLOS instance contains a reference to a C "table" object <br>
(allocated on C-heap by foreign library). If a caller in a Lisp
program <br>
ignores the returned "table" object, it should be garbage
collected <br>
as expected. <br>
<br>
My questions are now:<br>
1) Will it be really garbage collected?<br>
2) If the answer is in affirmative, is it garbage collected
correctly <br>
(no potential memory leaks)? <br>
<br>
Please note that the C API offers as mentioned above <br>
its own dedicated function for that purpose.<br>
<br>
What would be a correct solution to avoid memory leaks in this
situation? <br>
Using a finalizer seems to be a possible way to go. But I'm not
sure how <br>
this can be done by just using the finalizer parameters "object"
and "function" <br>
where "function" can't reliablely access "object" (cf.
documentation of finalizer <br>
in "trivial-garbage" package)!!<br>
<br>
Any help and feedback is very much appreciated!<br>
<br>
Regards<br>
Nik<br>
<br>
<br>
</font>
</body>
</html>