From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: weis Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id KAA09644 for caml-redistribution; Tue, 18 Mar 1997 10:47:11 +0100 (MET) Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id UAA28453 for ; Mon, 17 Mar 1997 20:19:02 +0100 (MET) Received: from tobago.inria.fr (tobago.inria.fr [128.93.8.21]) by concorde.inria.fr (8.7.6/8.7.3) with ESMTP id UAA04512 for ; Mon, 17 Mar 1997 20:19:01 +0100 (MET) Received: (from doligez@localhost) by tobago.inria.fr (8.6.10/8.6.6) id UAA04633 for caml-list@pauillac.inria.fr; Mon, 17 Mar 1997 20:19:00 +0100 Date: Mon, 17 Mar 1997 20:19:00 +0100 From: Damien Doligez Message-Id: <199703171919.UAA04633@tobago.inria.fr> To: caml-list@pauillac.inria.fr Subject: Re: Weak pointers Sender: weis >From: Frank Christoph > Does this mean that even a full weak pointer can be erased? Yes. An empty pointer doesn't contain anything, so talking about erasure is only meaningful for full pointers. > What does "at any time" mean --- even if the pointer is still >accessible from the root set, its contents can be erased? Yes, but if that object is still reachable through some normal (non-weak) pointer (i.e. any object except a weak array), then the GC will not erase that weak pointer. In other words, the GC will only erase a weak pointer if this erasure makes the object unreachable, thus deallocatable. > Is this intended to contrast with a usual reference, which must >always be initialized? I think initialisation is irrelevant. > Are weak pointers intended to model C pointers? No. Weak pointers are essentially a GC feature: pointers that are not considered as making the pointed object reachable. > Could someone post an example of their use? You can use them to implement hash-consing. Assume you have some tree data structure. If you want to share the nodes wherever possible, you can put every created node into a hash table. Then when you are about to create a new node, you first look in the hash table to see if the same node has already been created. If this is the case, you return the old one from the hash table instead of creating a new one. But the above prevents the GC from collecting the nodes when they become unused, because they will always be reachable from the hash table. If you use weak pointers in your hash table, the GC will be able to deallocate the dead nodes, but you still can have access to the live ones through the weak pointers. I don't have the weak hash table code yet, but it will certainly be in the library at some point in the future. Hope this helps. If it's not clear, please ask more questions. -- Damien