In SCIP.jl, we build a wrapper for a C library. There’s a Julia type SCIPModel
that basically holds a Pointer to a C struct. In the constructor, we call a corresponding initializer of the C library that allocates significant memory. The destructor is then called in the finalizer of our Julia type.
Generally, the garbage collection works find: At some point, when our Julia type is out of scope, it will be finalized and the memory of the C library freed as well. But I’ve noticed that this garbage collection is sometimes delayed a lot, to the point that my machine freezes because it runs out of memory (see PR #34.)
My guess is that Julia knows when to call gc()
before it runs out of memory, but it only knows about its own memory, not the implicitely allocated one. So my question is: Can I make Julia’s GC aware of the (rought amount of) memory that belongs to some of its objects?