From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id p51CeNAb019168 for ; Wed, 1 Jun 2011 14:40:23 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AjoDAM0y5k3RVdK2kWdsb2JhbAA9AQMSmBGNLV4IFAEBAQEJCQ0HEieoOoJCjB6COYQ0OYhiAQEDBoYaBJBVizI7g0A X-IronPort-AV: E=Sophos;i="4.65,303,1304287200"; d="scan'208";a="95863218" Received: from mail-iy0-f182.google.com ([209.85.210.182]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/RC4-SHA; 01 Jun 2011 14:40:10 +0200 Received: by iyj12 with SMTP id 12so7794555iyj.27 for ; Wed, 01 Jun 2011 05:40:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:date:message-id:subject:from:to :content-type; bh=NNdja7exaYpZaG4MmD7oNPPdblWKeQJ4qWFbs95luh8=; b=OgPOHEMfXrDbaC5CuwVMBvnpJnFO7O63kZRA6R1Ckdx++uTTDk5PrH4x75Dchk2kzJ RFsTC+8ZEk0sSU/b9rsV0jJ+tKgOovaSHEl12Bi7J3ipBHEZDVD3qLXrfVc9ZO3BA4Mo r0aZcZMeOGcWI/Tg7aG3s6j32iMzBeuYCoQRA= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; b=QybUwWao40IfT91zkb3yof88bhSXI3fpj+eV6wWxmSATQAQDZXfsRbUtmwLyl2K2pM gjVkrnKEf6kwFpvkoKVpBojleD0wk8L9ZycyU57zVQeiTeNOz06m3k8mIxMaoCPunwE6 6oqKHir4ZPT8+BfMIhLqJdAkNUtKFM/oI3S4M= MIME-Version: 1.0 Received: by 10.42.77.4 with SMTP id g4mr10744314ick.322.1306932006402; Wed, 01 Jun 2011 05:40:06 -0700 (PDT) Received: by 10.231.2.209 with HTTP; Wed, 1 Jun 2011 05:40:06 -0700 (PDT) Date: Wed, 1 Jun 2011 14:40:06 +0200 Message-ID: From: Hans Ole Rafaelsen To: caml-list@inria.fr Content-Type: multipart/alternative; boundary=20cf3005da46fcbca204a4a5d1da Subject: [Caml-list] Finding memory leakage using Gc module --20cf3005da46fcbca204a4a5d1da Content-Type: text/plain; charset=ISO-8859-1 Hi, is there some way to monitor memory being allocated (and still in use) when calling a function? In the first case below it should report close to 0 and in the second close to 10240. But here it reports 10368 in both cases. Gc.allocated_bytes seems to report allocated bytes without reporting what it was able to free. Have also tried other Gc functions such as Gc.counters. Is it some way to find out which bytes have been allocated and not freed after calling a function? Is there some good methods that people use to find out (get a hint of) which memory is leaking? First: let str = ref "" in Gc.full_major (); let before = Gc.allocated_bytes () in str := String.create 10240; str := ""; Gc.full_major (); let after = Gc.allocated_bytes () in let delta = after -. before in Printf.printf "Bytes used: %f\n%!" delta; Second: Gc.full_major (); let before = Gc.allocated_bytes () in str := String.create 10240; Gc.full_major (); let after = Gc.allocated_bytes () in let delta = after -. before in Printf.printf "Bytes used: %f\n%!" delta; Regards, Hans Ole Rafaelsen --20cf3005da46fcbca204a4a5d1da Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Hi,

is there some way to monitor memory being allocated (and still i= n use) when calling a function? In the first case below it should report cl= ose to 0 and in the second close to 10240. But here it reports 10368 in bot= h cases.
Gc.allocated_bytes seems to report allocated bytes without reporting what = it was able to free. Have also tried other Gc functions such as Gc.counters= . Is it some way to find out which bytes have been allocated and not freed = after calling a function? Is there some good methods that people use to fin= d out (get a hint of) which memory is leaking?

First:
=A0=A0=A0 =A0=A0=A0 let str =3D ref "" in
=A0=A0= =A0 =A0=A0=A0 Gc.full_major ();
=A0=A0=A0 =A0=A0=A0 let before =3D Gc.al= located_bytes () in
=A0=A0=A0 =A0=A0=A0 str :=3D String.create 10240;=A0=A0=A0 =A0=A0=A0 str :=3D "";
=A0=A0=A0 =A0=A0=A0 Gc.full_= major ();
=A0=A0=A0 =A0=A0=A0 let after =3D Gc.allocated_bytes () in
=A0=A0=A0 =A0= =A0=A0 let delta =3D after -. before in
=A0=A0=A0 =A0=A0=A0 Printf.print= f "Bytes used: %f\n%!" delta;

Second:
=A0=A0=A0 =A0=A0= =A0 Gc.full_major ();
=A0=A0=A0 =A0=A0=A0 let before =3D Gc.allocated_by= tes () in
=A0=A0=A0 =A0=A0=A0 str :=3D String.create 10240;
=A0=A0=A0 =A0=A0=A0 Gc= .full_major ();
=A0=A0=A0 =A0=A0=A0 let after =3D Gc.allocated_bytes () = in
=A0=A0=A0 =A0=A0=A0 let delta =3D after -. before in
=A0=A0=A0 =A0= =A0=A0 Printf.printf "Bytes used: %f\n%!" delta;


Regards,

Hans Ole Rafaelsen
--20cf3005da46fcbca204a4a5d1da--