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] Modifying heap from custom finalizers?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2004-01-03 (13:47)
From: Damien Doligez <damien.doligez@i...>
Subject: Re: [Caml-list] Modifying heap from custom finalizers?
On Monday, December 29, 2003, at 09:25 AM, Nuutti Kotivuori wrote:

> I am wonder how evil of a deed would I be doing to the garbage
> collector by modifying the heap in the finalizer of a custom block.

Ouch !  Tricky questions ahead !

> Apparently the finalizers are run during the sweep phase of the major
> garbage collector. If I there change a value from the global table to
> the unit value -

I think that should work.

>  But, what about anything more?

It's hard to tell what will break the invariants of the GC.  My
recommendation is that you do none of the following.

>  Assigning values?

I guess it would work, as long as you're not making anything
point to the minor heap (see below), and that you're not getting
the values from weak arrays, and maybe some other strange corner

>  Creating new values?

No.  There might be a way to make it work, but it'll be so hairy
I don't even want to think about it.

>  Do I have to make sure the small heap stays empty?

If you allocate in the minor heap, it can trigger a minor
collection, which will reenter the major GC, maybe even call the
compactor.  Crash.

>  And if zeroing the value at sweep phase makes the values pointed by it
> garbage collected only at the next collection, is there any I can
> speed up the process?

What makes you think there is no other pointer to these values ?
And to the things pointed by these values ?

> I could find no documentation what you can and what you can't do in
> the finalizers for custom blocks.

You should enter this in the bug tracking system as a feature wish.

-- Damien

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