Version française
Home     About     Download     Resources     Contact us    
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: -- (:)
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
first.

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
subsequently.

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
completed.

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, mailto:skaller@users.sf.net
voice: 061-2-9660-0850, 
snail: PO BOX 401 Glebe NSW 2037 Australia
Checkout the Felix programming language http://felix.sf.net



-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners