Delivered-To: garrigue at math.nagoya-u.ac.jp Authentication-Results: mailhost.math.nagoya-u.ac.jp sender=lablgtk-bounces at yquem.inria.fr; domainkey=neutral (no query protocol specified; no policy for yquem.inria.fr) Delivered-To: lablgtk at yquem.inria.fr DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to :subject:mime-version:content-type; bh=KEP0yoA7gVQ4oPB4FX5zrrYHZetkozBrxE+JBzhrMO8=; b=HgfWj7kkd3SKel2DgDn9Mh0xSfRuw8E6+RjN4wdkuK0mO9zEUgsKM33Ou5GU7b2OXb aUd5WCraGJyQtllHxLAv+MoVvJQK1Od9OgIjKvkNvfYyNouEEAL126ar6po2half3UJK yDA4yjqOOweFSXOVfOQpNRljO1HUF/5S7Cc78= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:mime-version:content-type; b=qHaBZ4RSYPxQ3JitsaTNApGbE99VaMEZ8Nazq51L7UPMKk3RZx6D8UwW7KonxRYacb Uq27CfxQtVyTtVvFQyEA9Mcg3A1EOUs7pDx/Z9E9ELbNHRqdm8y4qTQ0MfJQBiZaA1n8 lBcvFRqcNtvSGZqKjtHR1My9L14n4/LXlxwGU= Message-ID: Date: Sun, 26 Oct 2008 21:53:22 -0400 From: "Jacques Le Normand" To: lablgtk at yquem.inria.fr MIME-Version: 1.0 Subject: [Lablgtk] memory leak, destroying widgets Content-Type: multipart/mixed; boundary="===============0434122004==" Mime-version: 1.0 --===============0434122004== Content-Type: multipart/alternative; boundary="----=_Part_19077_1739791.1225072402036" ------=_Part_19077_1739791.1225072402036 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline Hello lablgtk, I'm getting a memory leak in my program because, when I destroy a widget, the memory does not get freed. I thought it would be done automatically when I call #remove from the container, but this does not seem to be the case. How can I destroy my widgets and make sure the memory is cleared? I've tried 2 or 3 different ways, with the same result. Here is a program that creates and destroys 100 GEdit.entry every 200ms. At every iteration, I call Gc.allocated_bytes . The number printed keeps going up (showing that there is a memory leak.) I posted it a week ago. I've gotten a couple of people to run it and they all get the same result. If more people could run it to make sure, that would be greatly approciated. cheers --Jacques let repeat n f = let rec rep i = if i = n then [] else (f () :: rep (i+1)) in rep 0 let container_clear c = List.iter c#remove c#all_children let _ = let source_window = GWindow.window ~width:100 ~height:100 () in let vbox = GPack.vbox ~packing:source_window#add () in let inside = ref false in let fill_vbox () = if !inside then () else begin inside := true; let add_entry () = let ret = GEdit.entry () in vbox#pack (ret:>GObj.widget); ret in container_clear vbox; print_endline (string_of_float (Gc.allocated_bytes ())); ignore(repeat 100 add_entry); inside:=false end in ignore(Glib.Timeout.add 200 (fun () -> fill_vbox (); true)); source_window#show (); GMain.Main.main () ------=_Part_19077_1739791.1225072402036 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline Hello lablgtk,
I'm getting a memory leak in my program because, when I destroy a widget, the memory does not get freed. I thought it would be done automatically when I call #remove from the container, but this does not seem to be the case. How can I destroy my widgets and make sure the memory is cleared? I've tried 2 or 3 different ways, with the same result.
Here is a program that creates and destroys 100 GEdit.entry every 200ms. At every iteration, I call  Gc.allocated_bytes . The number printed keeps going up (showing that there is a memory leak.) I posted it a week ago. I've gotten a couple of people to run it and they all get the same result. If more people could run it to make sure, that would be greatly approciated.
cheers
--Jacques


let repeat n f =
  let rec rep i =
    if i = n then [] else (f () :: rep (i+1))
  in
    rep 0


let container_clear c =
  List.iter c#remove c#all_children

let _ =
  let source_window = GWindow.window ~width:100 ~height:100 () in
  let vbox = GPack.vbox ~packing:source_window#add () in
  let inside = ref false in
  let fill_vbox () =
    if !inside then
      ()
    else
      begin
    inside := true;
    let add_entry () =
      let ret = GEdit.entry ()
      in
        vbox#pack (ret:>GObj.widget);
        ret
    in
      container_clear vbox;
      print_endline (string_of_float  (Gc.allocated_bytes ()));
      ignore(repeat 100 add_entry);     
      inside:=false
      end
  in
    ignore(Glib.Timeout.add 200 (fun () -> fill_vbox (); true));
    source_window#show ();
    GMain.Main.main ()

------=_Part_19077_1739791.1225072402036-- --===============0434122004== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Lablgtk mailing list Lablgtk@yquem.inria.fr http://yquem.inria.fr/cgi-bin/mailman/listinfo/lablgtk --===============0434122004==--