From: Hao-yang Wang <hao-yang_wang@filemaker.com>
To: <caml-list@inria.fr>
Subject: Strange memory leak
Date: Fri, 9 Feb 2001 13:08:57 -0800 [thread overview]
Message-ID: <200102092101.NAA02332@imap.filemaker.com> (raw)
I wrote this bunch of code:
-----------------------------------
type 'a zlist = Znull | Zcons of 'a * 'a zzlist
and 'a zzlist = 'a zlist Lazy.t
let rec zfilter f zz =
let z = Lazy.force zz in
match z with
Znull ->
Znull
| Zcons(head, ztail) ->
if f head then
z
else
zfilter f ztail
let rec build_list n =
if n > 0 then
Zcons(n, lazy (build_list (n - 1)))
else
Znull
let rec loopy f zz =
match zfilter f zz with
Znull ->
()
| Zcons(head, ztail) ->
loopy f ztail
-----------------------------------
>From the byte-code toplevel, the following expression evaluates fine
loopy (fun x -> true) (lazy (build_list 1000000));;
while the following expression produces "Fatal error: out of memory."
loopy (fun x -> false) (lazy (build_list 1000000));;
Why? In particular, the function zfilter looks tail-recursive to me.
I am using ocaml-3.00, with the Macintosh version of top-level.
Thanks,
Hao-yang Wang
next reply other threads:[~2001-02-10 21:27 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-02-09 21:08 Hao-yang Wang [this message]
2001-02-09 23:41 Hao-yang Wang
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=200102092101.NAA02332@imap.filemaker.com \
--to=hao-yang_wang@filemaker.com \
--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).