<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE message PUBLIC
  "-//MLarc//DTD MLarc output files//EN"
  "../../mlarc.dtd"[
  <!ATTLIST message
    listname CDATA #REQUIRED
    title CDATA #REQUIRED
  >
]>

  <?xml-stylesheet href="../../mlarc.xsl" type="text/xsl"?>


<message 
  url="2003/12/17a764809903dd9118a09590699d8f47"
  from="Damien Doligez &lt;damien.doligez@i...&gt;"
  author="Damien Doligez"
  date="2003-12-16T22:54:22"
  subject="Re: [Caml-list] Garbage collection and a reference counting library "
  prev="2003/12/7705bdf1a3ecb740b46d00b434db07f4"
  next="2003/12/88bc90aa6873274d55aa4e3daf5c5256"
  prev-in-thread="2003/12/273818949a6b419c61c9cef3c10d64bf"
  prev-thread="2003/12/0a730e95e9a98ca965d70ceb4206faf5"
  next-thread="2003/12/b218a258251a78c1b945b8dfd7846220"
  root="../../"
  period="month"
  listname="caml-list"
  title="Archives of the Caml mailing list">

<thread subject="[Caml-list] Garbage collection and a reference counting library ">
<msg 
  url="2003/12/23761d3eb8a5f461976c2334cc53cb1c"
  from="Richard Jones &lt;rich@a...&gt;"
  author="Richard Jones"
  date="2003-12-11T14:36:46"
  subject="[Caml-list] Garbage collection and a reference counting library ">
<msg 
  url="2003/12/222cf89526a65ce589d277efdd2829d4"
  from="Jean-Christophe Filliatre &lt;filliatr@l...&gt;"
  author="Jean-Christophe Filliatre"
  date="2003-12-11T15:29:27"
  subject="Re: [Caml-list] Garbage collection and a reference counting library ">
<msg 
  url="2003/12/273818949a6b419c61c9cef3c10d64bf"
  from="David Brown &lt;caml-list@d...&gt;"
  author="David Brown"
  date="2003-12-11T16:57:44"
  subject="Re: [Caml-list] Garbage collection and a reference counting library">
</msg>
</msg>
<msg 
  url="2003/12/17a764809903dd9118a09590699d8f47"
  from="Damien Doligez &lt;damien.doligez@i...&gt;"
  author="Damien Doligez"
  date="2003-12-16T22:54:22"
  subject="Re: [Caml-list] Garbage collection and a reference counting library ">
</msg>
</msg>
</thread>

<contents>
On Thursday, December 11, 2003, at 03:36 PM, Richard Jones wrote:

&gt; I wrote an interface to allow OCaml to call Perl code and libraries.
&gt; This interface doesn't pay much attention to collecting memory
&gt; correctly.  In particular when a Perl SV (scalar value) is allocated
&gt; and passed to us, it will have a Perl internal link count of, say, 1,
&gt; and we never decrement that link count, so Perl will never free it.
[...]
&gt; I imagine that what I should do is to add a finalization function, so
&gt; that when 'rv' is garbage collected, I should decrement the Perl link
&gt; count, thus forcing Perl to free the associated SV.

Yes, this is the canonical example of using finalized blocks.

&gt; Is this safe though?  Can OCaml copy this object, and collect one of
&gt; them, thus causing the SV to be deallocated early?  Do I need another
&gt; 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

</contents>

</message>

