From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id XAA15277; Tue, 16 Dec 2003 23:54:22 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id XAA15390 for ; Tue, 16 Dec 2003 23:54:21 +0100 (MET) Received: from inria.fr (planar.net0.nerim.net [213.41.168.102]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id hBGMsJX11070 for ; Tue, 16 Dec 2003 23:54:20 +0100 (MET) Date: Tue, 16 Dec 2003 23:55:13 +0100 Subject: Re: [Caml-list] Garbage collection and a reference counting library Content-Type: text/plain; charset=US-ASCII; format=flowed Mime-Version: 1.0 (Apple Message framework v553) From: Damien Doligez To: caml-list@inria.fr Content-Transfer-Encoding: 7bit In-Reply-To: <20031211143640.GA21082@redhat.com> Message-Id: X-Mailer: Apple Mail (2.553) X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 damien:01 damien:01 scalar:01 finalization:01 deallocated:01 indirection:01 finalization:01 ocaml:01 ocaml:01 garbage:01 garbage:01 doligez:01 doligez:01 canonical:03 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Thursday, December 11, 2003, at 03:36 PM, Richard Jones wrote: > I wrote an interface to allow OCaml to call Perl code and libraries. > This interface doesn't pay much attention to collecting memory > correctly. In particular when a Perl SV (scalar value) is allocated > and passed to us, it will have a Perl internal link count of, say, 1, > and we never decrement that link count, so Perl will never free it. [...] > I imagine that what I should do is to add a finalization function, so > that when 'rv' is garbage collected, I should decrement the Perl link > count, thus forcing Perl to free the associated SV. Yes, this is the canonical example of using finalized blocks. > Is this safe though? Can OCaml copy this object, and collect one of > them, thus causing the SV to be deallocated early? Do I need another > layer of indirection between 'rv' and the SV? Of course it is safe. It is guaranteed that each allocation of a finalized block corresponds to at most one call of its finalization function. Otherwise, finalization would be much less useful. -- Damien ------------------- 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