Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Damien Doligez <damien.doligez@inria.fr>
To: caml-list@inria.fr
Subject: Re: [Caml-list] Garbage collection and a reference counting library
Date: Tue, 16 Dec 2003 23:55:13 +0100	[thread overview]
Message-ID: <E87D546B-301A-11D8-9FCB-00039310CAE8@inria.fr> (raw)
In-Reply-To: <20031211143640.GA21082@redhat.com>

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


      parent reply	other threads:[~2003-12-16 22:54 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-12-11 14:36 Richard Jones
2003-12-11 15:14 ` Jean-Christophe Filliatre
2003-12-11 16:57   ` David Brown
2003-12-16 22:55 ` Damien Doligez [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=E87D546B-301A-11D8-9FCB-00039310CAE8@inria.fr \
    --to=damien.doligez@inria.fr \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox