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
[Caml-list] Garbage collecting _everything_
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2004-06-05 (16:30)
From: skaller <skaller@u...>
Subject: Re: [Caml-list] Garbage collecting _everything_
On Sun, 2004-06-06 at 01:36, Roberto Bagnara wrote:

> Isn't `at_exit Gc.full_major;;' supposed to collect
> _everything_ at program termination time?

Here is what it says about at_exit:

Register the given function to be called at program termination time.
The functions registered with at_exit will be called when the program
executes Pervasives.exit, or terminates, either normally or because of
an uncaught exception. The functions are called in ``last in, first
out'' order: the function most recently added with at_exit is called

Now, since these functions are *arbitrary*, performing a collection
at some particular time will do just the same as it always does:
collect unreachable objects.

Clearly, global variables created thusly:

let x = create_object () 

may be visible to any function defined in the same scope

It is likely such variables must be considered
visible to all functions. In other words, they all must
be roots. The only time these objects could possibly
be released is after all user code has executed,
and that would be after all 'at_exit' functions have

So I am guessing that you made the mistake of
placing two of your C++ objects in Ocaml global variables.

Make sure the bindings for you test objects are
to variables local to a test function which terminates
and leaves its locals unreachable. You can simply call
Gc.full_major after invoking the test function.

John Skaller,
voice: 061-2-9660-0850, 
snail: PO BOX 401 Glebe NSW 2037 Australia
Checkout the Felix programming language

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: