caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Xavier Leroy <xavier.leroy@inria.fr>
To: Basile STARYNKEVITCH <basile@starynkevitch.net>
Cc: David Brown <caml-list@davidb.org>, Caml List <caml-list@inria.fr>
Subject: Re: [Caml-list] Memory leak with native code.
Date: Sat, 7 Dec 2002 11:42:36 +0100	[thread overview]
Message-ID: <20021207114236.B23052@pauillac.inria.fr> (raw)
In-Reply-To: <15855.46993.822199.934318@hector.lesours>; from basile@starynkevitch.net on Thu, Dec 05, 2002 at 09:31:13PM +0100

>     David> I have a fairly complex program that has numerous callbacks
>     David> between Ocaml, C and back to Ocaml (I'm using Debian's
>     David> 3.06).
> 
>     David> If I compile my program byte-code, it works well.
> 
>     David> However, if I compile it native, it seems to leak memory,
>     David> just consuming more and more memory as it runs.
> 
> I assume your plateform is x86 on Debian. Because of the small number
> of registers, tail-recursion is limited to 5 arguments (if my memory
> serves me well). For more arguments, a tail-rec is not a loop on x86.

As of release 3.06, tail recursion (tail calls to the same function)
are properly implemented on all platforms regardless of the number of
arguments.  Tail cross-recursion, or more generally tail calls to
another function, are not supported if the number of arguments is
greater than a processor-dependent number: 5 for x86, more for RISC
processors.  

That would explain why a program compiled to native code uses more
stack space than when compiled to byte code.  However, there is no
evidence that David's problem is related to stack space.

You can track Caml heap space consumption by running both programs
(native and byte-code) with the OCAMLRUNPARAM environment variable set
to "v=4".  Normally, you should see roughly the same sequences of
"Growing heap to ..." messages.

A third source of leaks is the C code itself.  A good tool to track
these leaks is valgrind.

- Xavier Leroy
-------------------
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


  reply	other threads:[~2002-12-07 10:43 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-12-05 18:48 David Brown
2002-12-05 19:14 ` Markus Mottl
2002-12-05 20:31 ` Basile STARYNKEVITCH
2002-12-07 10:42   ` Xavier Leroy [this message]
2002-12-07 21:52     ` David Brown

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=20021207114236.B23052@pauillac.inria.fr \
    --to=xavier.leroy@inria.fr \
    --cc=basile@starynkevitch.net \
    --cc=caml-list@davidb.org \
    --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;
as well as URLs for NNTP newsgroup(s).