[racket] Calling collect-garbage does not work during a FFI call?
Hi,
I'm using MzScheme v4.2.4, and I'm trying to use the CUDD Binary
Decision Diagram (BDD) library, which is implemented in C. CUDD
manages all the BDDs with reference counting and its own garbage
collector. In my scheme code I would like to have all the reference
counting automated. What I did is have the functions create new BDDs
to automatically increment the reference counts, and then use
register-finalizer to decrement the reference count. I understand how
to do all this, and it works.
The problem is that I need to sync up the CUDD garbage collector and
the Scheme garbage collector. I want the Scheme garbage collector to
be called right before the CUDD garbage collector is called, so that
when BDD nodes are unreachable by Scheme, their reference counts go to
0, and CUDD can collect them. CUDD provides a hook to have a function
called right before garbage collection occurs, so I thought this
should be simple. The problem is that the collect-garbage calls in the
hook appear to do nothing. None of the finalizers are called when I
rely on the hook, but if I explicitly call collect-garbage, then the
finalizers are called.
I know the finalizers are called because I print a message in them,
and I know the hook function is being called, because I print out a
message in the hook function. I cannot just call collect-garbage
myself, because the CUDD garbage collection is called by the package
itself at unknown times. Operations internal to the package can cause
a garbage collection at any time. I have tried to call
scheme_collect_garbage from C, in a hook function implemented in C.
And, I have implemented the hook in scheme, and had passed the
function to the C procedure that registers the hook. For both methods,
the hook is called, and collect-garbage doesn't work.
Is garbage collection disabled or something during a FFI call? Is
there another solution?
Thanks,
Nick