Allocates memory for a list of foreign objects, executes a list of forms which may use the objects across the scope of the macro, and then deallocates the foreign objects.
A list of variable bindings.
A single form to be executed with bindings in effect.
A list of forms.
The macro
with-dynamic-foreign-objects-with-cleanups
allocates memory for foreign objects specified in
bindings
, executes
form
(which may use those objects) and then executes
cleanups
before deallocating the foreign objects. This is the same effect as with-dynamic-foreign-objects, but it also allows you to add cleanup forms
cleanups
that are guaranteed to be executed (as in
unwind-protect
).
There are two differences between using this and using with-dynamic-foreign-objects with a body is that is a single
unwind-protect
form where
cleanups
are the cleanup-forms of the
unwind-protect
, like this:
(fli:with-dynamic-foreign-objects bindings
(unwind-protect form
cleanups ))
Firstly, the
with-dynamic-foreign-objects-with-cleanups
form is smaller and faster.
Secondly, if there is an error in any of the cleanups with-dynamic-foreign-objects will cause a memory leak, but this will not happen when using
with-dynamic-foreign-objects-with-cleanups
.