From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id A0C7EBB81 for ; Fri, 31 Dec 2004 10:39:59 +0100 (CET) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id iBV9dxG4000464 for ; Fri, 31 Dec 2004 10:39:59 +0100 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 KAA13626 for ; Fri, 31 Dec 2004 10:39:58 +0100 (MET) Received: from smtp8.wanadoo.fr (smtp8.wanadoo.fr [193.252.22.23]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id iBV9dw4r000457 for ; Fri, 31 Dec 2004 10:39:58 +0100 Received: from me-wanadoo.net (localhost [127.0.0.1]) by mwinf0812.wanadoo.fr (SMTP Server) with SMTP id 64D7C1C0020B for ; Fri, 31 Dec 2004 10:39:58 +0100 (CET) Received: from [192.168.0.102] (AStrasbourg-251-1-17-222.w82-126.abo.wanadoo.fr [82.126.207.222]) by mwinf0812.wanadoo.fr (SMTP Server) with ESMTP id 7220D1C001ED for ; Fri, 31 Dec 2004 10:39:56 +0100 (CET) Received: from 127.0.0.1 (AVG SMTP 7.0.298 [265.6.7]); Fri, 31 Dec 2004 10:35:51 +0100 Message-ID: <41D51D75.5010406@wanadoo.fr> Date: Fri, 31 Dec 2004 10:35:49 +0100 From: Matthieu Brucher User-Agent: Mozilla Thunderbird 1.0 (Windows/20041206) X-Accept-Language: en-us, en Cc: caml-list@inria.fr Subject: Re: [Caml-list] memory leak in C snippet? References: <2D67CB0C-5907-11D9-B386-000A95A068A6@reddwarf.xs4all.nl> In-Reply-To: <2D67CB0C-5907-11D9-B386-000A95A068A6@reddwarf.xs4all.nl> Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=ISO-8859-1; format=flowed X-Miltered: at concorde with ID 41D51E6F.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at concorde with ID 41D51E6E.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; matthieu:01 matthieu:01 caml-list:01 ocaml:01 blocs:01 alloc:01 alloc:01 ocaml:01 wrote:01 camlprim:01 camlparam:01 val:01 val:01 camlreturn:01 usr:01 X-Spam-Checker-Version: SpamAssassin 3.0.0 (2004-09-13) on yquem.inria.fr X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.0 X-Spam-Level: Hello I'm not very into Ocaml at the moment, so perhaps what I will say isn't relevant, but you seem to allocate 2 memory blocs in your function (alloc_string and alloc_tuple), but where do you free this memory ? Does OCaml take charge of this or do you still have to do it yourself as it is in a C function ? Happy new year. Matthieu Lodewijk Voge wrote: > hello, > > I'm writing a daemon in ocaml with some glue code in C. it all works > fine, except memory seems to leak to a point the daemon can last > only about a week on the smallest systems. after a lot of removing > code I come to this snippet that seems to leak: > > external bar: unit -> Unix.inet_addr * unit = "bar" > > let _ = > let s = String.create 392 in > while true do > ignore(bar ()); > done > > with > > CAMLprim value bar(value unit) { > CAMLparam1(unit); > CAMLlocal2(res, addr); > int i; > > addr = alloc_string(4); > *(int *)(String_val(addr)) = htonl(0xac100000); > res = alloc_tuple(2); > Store_field(res, 0, addr); > Store_field(res, 1, Val_unit); > CAMLreturn(res); > } > > which gives when run: > > ~/test$ while /usr/bin/true; do ps -o rss -p 15696 | tail -1; sleep 2; > done > 784 > 784 > 788 > 792 > 796 > 800 > 804 > 808 > 812 > ^C > > an ever growing RSS. strangely, having bar() return just the alloced > string instead of a tuple, this doesn't occur. even more strangely, if > I delete the let s = String.make 392 line, it doesn't occur either. > systems tested are MacOS X, FreeBSD (the target system) and Linux. as > the RSS approaches the segment size that'll expand too, and this > gobbles up all available virtual memory in a week on the smallest > target systems. > > so, my question is: can anyone see an obvious error in the C snippet? > some violation of the rules in the manual I missed? > > thanks, > Lodewijk -- No virus found in this outgoing message. Checked by AVG Anti-Virus. Version: 7.0.298 / Virus Database: 265.6.7 - Release Date: 30/12/2004