Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
Final_tag and garbage collection
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 1995-11-07 (12:48)
From: Robbert VanRenesse <rvr@c...>
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

Any ideas?