-
Notifications
You must be signed in to change notification settings - Fork 73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
investigate whether CFFI frees C-allocated memory for :string
return types
#221
Comments
:string
arguments:string
return types
If YES, we should add a comment. If NO, we should fix it. |
It appears the memory is not freed by cffi. The cffi docs say
which is somewhat ambiguous and makes it seem like maybe the foreign string would be freed, but on further review I think the above only refers to strings passed as arguments to foreign functions which were allocated by cffi as part of the lisp->cstring conversion. For strings returned from foreign functions, the magic happens in the generic function
You can see the memory is freed only when
This is easy to verify in the REPL
Just to be sure, I modified
This actually makes some sense as a default behavior, since cffi can't really know for an arbitrary C function returning Possible workaroundsCaveat lector: I haven't tested any of these beyond REPL-poking. Option 1: tell cffi to
|
@appleby This is a very great analysis. I think the option to the |
If no one beats me to it, I will send a PR later adding the
This was my first peek under the hood of cffi, and I was suitably impressed. Defaults are sane but with plenty of knobs for when you need more control. For example, when defining your own foreign types, you can avoid the overhead of method dispatch for the |
Tweedledum integration makes use of this, and if it's not, it'll be a slow memory leak.
The text was updated successfully, but these errors were encountered: