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] Weak pointers and Gc.finalise
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2004-04-01 (17:07)
From: Damien Doligez <damien.doligez@i...>
Subject: Re: [Caml-list] Weak pointers and Gc.finalise
On Apr 1, 2004, at 06:48, Shivkumar Chandrasekaran wrote:

> I just noticed that if the only reference to a bigarray is in a Weak.t 
> array, and if there is a finalisation function set on the bigarray, 
> then that finalisation function is not necessarily called when the 
> entry in the Weak.t array is set to None. Rather it is potentially 
> called *much* later.

That's right.  Within a GC cycle, we first handle the weak pointers
that have to be erased, then we handle the finalised values.

> I am assuming that this is the right behaviour.

We have to do it that way because there might be several weak pointers
to the same value, and they have to be all erased before we call
the finalisation function.

> My question is, can I get the finalisation function to be called when 
> the weak pointer is being set to None?

I guess it might be possible to attach functions to weak pointers,
to be called when the weak pointer is erased, but that would be
different from finalisation functions, and it would need a large
amount of work to modify the GC.

> (Side note: I am trying to avoid Marshaling the Bigarray unless it is 
> going to be garbage-collected. But if I cannot detect that, then I 
> have to always Marshal it whenever its entries change, which is very 
> inefficient.)

I'm not sure I understand.  The finalisation function is called when
the value is about to be garbage-collected.  Why can't you just
marshal it at that point?

-- Damien

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