There are some C objects of which the memory is managed in C. We could use ForeignPtr rather than Ptr internally to emphasise that this memory is foreign-managed. Moreover, we could then attach finalisers to the ForeignPtr to ensure that the foreign-managed memory is freed when the corresponding ForeignPtr is garbage collected.
Example: CXToken structs are allocated by the libclang C library and they should be freed using clang_disposeTokens.
There are some C objects of which the memory is managed in C. We could use
ForeignPtrrather thanPtrinternally to emphasise that this memory is foreign-managed. Moreover, we could then attach finalisers to theForeignPtrto ensure that the foreign-managed memory is freed when the correspondingForeignPtris garbage collected.Example:
CXTokenstructs are allocated by thelibclangC library and they should be freed usingclang_disposeTokens.