Final_tag and garbage collection

Robbert VanRenesse (rvr@cs.cornell.edu)
Mon, 6 Nov 1995 14:33:02 -0500

From: Robbert VanRenesse <rvr@cs.cornell.edu>
Date: Mon, 6 Nov 1995 14:33:02 -0500
Message-Id: <199511061933.OAA01340@snotra.cs.cornell.edu>
To: caml-list@pauillac.inria.fr
Subject: Final_tag and garbage collection

The system that I'm building uses a mixture of C and CAML. Sometimes it is
necessary to have references from CAML objects to C objects. When CAML
cleans up its objects, the C objects need to be cleaned up as well. I'm
using the finalization functionality of CAML for that. However, it only
appears to work reliably in combination with alloc_shr(), not with alloc().
Here's the code:

value link;

link = alloc_shr(3, Final_tag);
Field(link, 0) = (value) link_final;
...

Very reliably, the function link_final is automatically invoked when the
system is garbage collecting. However, if I use alloc() instead, it
sometimes happens, but lots of blocks appear to not get finalized. I
used all of gc__minor, gc__major, and gc__fullmajor to try to provoke
finalization, but only a subset of what I allocated this way gets
finalized.

Any ideas?

Robbert