From: Hao-yang Wang <hywang@pobox.com>
To: <caml-list@inria.fr>
Subject: Re: Strange memory leak
Date: Fri, 9 Feb 2001 15:41:19 -0800 [thread overview]
Message-ID: <200102092334.PAA06312@imap.filemaker.com> (raw)
After I posted the last message, I think I have found out what's wrong.
In the function 'loopy', when it calls into 'zfilter f zz', the variable
zz keeps holding the head of the lazy list, thus prevents GC from
reclaiming the memory.
Still, I don't know how to rewrite loopy to plug this leak. Any help?
Thanks,
Hao-yang Wang
>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:36 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-02-09 23:41 Hao-yang Wang [this message]
-- strict thread matches above, loose matches on Subject: below --
2001-02-09 21:08 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=200102092334.PAA06312@imap.filemaker.com \
--to=hywang@pobox.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).