caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Goswin von Brederlow <goswin-v-b@web.de>
To: "ivan chollet" <ivan.chollet@free.fr>
Cc: "'David Allsopp'" <dra-news@metastack.com>, caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Re: ocaml sefault in bytecode: unanswered questions
Date: Sun, 09 Aug 2009 18:14:06 +0200	[thread overview]
Message-ID: <87zla955ip.fsf@frosties.localdomain> (raw)
In-Reply-To: <001001ca18c7$37b22220$a7166660$@chollet@free.fr> (ivan chollet's message of "Sun, 9 Aug 2009 09:58:43 +0200")

"ivan chollet" <ivan.chollet@free.fr> writes:

> :v="urn:schemas-microsoft-com:vml"
> xmlns:o="urn:schemas-microsoft-com:office:office"
> xmlns:w="urn:schemas-microsoft-com:office:word"
> xmlns:m="http://schemas.microsoft.com/office/2004/12/omml"
> xmlns="http://www.w3.org/TR/REC-html40">
>
> Definitely.:p>
>
> Actually I had my real-world case in mind, so let me explain further with the
> following snippet::p>
>
> :p> 
>
> let myfun = doSomeWork (); myref := List.filter somefilterfunction !myref
> in:p>
>
> List.iter myfun !myref:p>
>
> :p> 
>
> In this case, a new linked list is created in each iteration of the
> List.filter. (that is, a new list allocation):p>
>
> Then, if doSomeWork () does a lot of work and lots of allocations, the GC will
> be called on a regular basis while in function myfun. :p>
>
> Then List.iter is tail-recursive, so it doesn't push its successive arguments
> on the stack. So the successively created myref become unreachable while still
> iterating on them.:p>
>
> So my question is, how does the GC know whether all these myref created
> throughout the iteration are collectable or not? I'm curious about how these
> myref are tagged/untagged by the garbage collector. Maybe pointing me the
> relevant portions of the ocamlrun source code would be nice.:p>

The current value of each binding is on the stack and the GC knows
about that. In the tail-recursion the value on the stack is
successively replaced by newer ones while the old ones are forgotten.
The GC then marks everything known (reachable) as still being needed
and everything it can't reach recursively from the known values your
code can't reach either and the GC can free it.

But that isn't even what happens in your case. Your myref is not on
the stack and you do not create a new myref on every iteration. You
only change its value. The GC knows about the myref and it will be one
of the known (reachable) things the GC starts from.

MfG
        Goswin


  parent reply	other threads:[~2009-08-09 16:14 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-08-08 17:09 ivan chollet
2009-08-08 17:24 ` [Caml-list] " David Allsopp
2009-08-09  7:58   ` ivan chollet
2009-08-09 10:16     ` Michel Mauny
     [not found]     ` <001501ca18cc$d59a61a0$80cf24e0$@metastack.com>
2009-08-09 12:06       ` ivan chollet
2009-08-09 13:20         ` David Allsopp
2009-08-09 13:55         ` Alain Frisch
2009-08-09 14:13           ` ivan chollet
2009-08-09 18:56           ` Elnatan Reisner
2009-08-09 19:09             ` Alain Frisch
2009-08-10 13:22               ` Elnatan Reisner
2009-08-10 13:36                 ` Martin Jambon
2009-08-10 14:26                   ` Elnatan Reisner
2009-08-09 16:14     ` Goswin von Brederlow [this message]
2009-08-10  4:14       ` ivan chollet

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=87zla955ip.fsf@frosties.localdomain \
    --to=goswin-v-b@web.de \
    --cc=caml-list@yquem.inria.fr \
    --cc=dra-news@metastack.com \
    --cc=ivan.chollet@free.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;
as well as URLs for NNTP newsgroup(s).