Version française
Home     About     Download     Resources     Contact us    
Browse thread
Questions on replacing finalizers and memory footprints
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Alexandre Pilkiewicz <alexandre.pilkiewicz@p...>
Subject: Re: [Caml-list] Questions on replacing finalizers and memory footprints
Le Friday 07 December 2007 22:01:23 forum@x9c.fr, vous avez écrit :
> Le 7 déc. 07 à 20:54, Jean-Christophe Filliâtre a écrit :
> My mistake, I did not take into account the fact that if a block is
> moved by the
> garbage collector, its reference is updated in the hashtable *too*.
> Hence the termination guarantee.

I think the problem is with the hash function :

	let hash o = Hashtbl.hash (magic o : int)

If you put an object in the hash table, it is stored under a key that depends 
on it's address a1. Once it's moved by the GC to the address a2, its 
reference is changed to a2, but not its key which is still the hash of a1. So 
when you check after that if your object is allready in the hash table, you 
look under the key hash(a2) if it's allready there, but it's not ! And if you 
are very unlucky (and have very few memory), it might append several time.

One solution could be to store the objects in a normal list and to look at the 
entire list every time. It would be *much* slower on huge structures, but 
probably more "correct" (so if used only for debug purpose, why not..)

let node_list = ref []

let in_list o = List.memq o !node_list

let add_in_list o = node_list := o::!node_list

let reset_list () = node_list := []

-- 
Alexandre Pilkiewicz