From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id WAA26807 for caml-red; Sat, 10 Feb 2001 22:36:51 +0100 (MET) Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id AAA19820 for ; Sat, 10 Feb 2001 00:34:24 +0100 (MET) Received: from ftp.filemaker.com (ftp.filemaker.com [192.35.50.27]) by concorde.inria.fr (8.11.1/8.10.0) with ESMTP id f19NYMP23192 for ; Sat, 10 Feb 2001 00:34:23 +0100 (MET) Received: from imap.filemaker.com (imap.filemaker.com [17.184.4.101]) by ftp.filemaker.com (8.9.0/8.9.0) with ESMTP id PAA21309 for ; Fri, 9 Feb 2001 15:34:13 -0800 (PST) Received: from [17.184.16.95] ([17.184.16.95]) by imap.filemaker.com (8.9.3/8.9.0) with SMTP id PAA06312 for ; Fri, 9 Feb 2001 15:34:14 -0800 (PST) Message-Id: <200102092334.PAA06312@imap.filemaker.com> Subject: Re: Strange memory leak Date: Fri, 9 Feb 2001 15:41:19 -0800 x-sender: hao-yang_wang@mail.filemaker.com x-mailer: Claris Emailer 2.0v3, January 22, 1998 From: Hao-yang Wang To: Mime-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Sender: weis@pauillac.inria.fr 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