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=BNwBqIjMkQFhTWkFeVUcg6uhDPusWqBJ2XRpeeL9Ukk=; b=DYyYzRfTCdNAKI8dgldclBHCmHZ4s6rjhkbc5S0/kd7fStvCs68iB8UwkqAZmzYPAZ xcQ+gIWMZxtPXTf7U35aQdCZIBkYwtMcoLW62jX0wCzkuDwtn6DpJql7iCbxrBOfLwyw 3bc6fs6yhHSW5TvBf7D0qeATBnpeTQsPCXrTw= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:mime-version:content-type; b=miVLp7hKVlRjkhugMlaqXyV1EoRVDloqZgifeZZO34tvzHn/QM0Hes49G37prEM2Bk GDwLzHbNA5R5qoeY0lbS8RGcVF1lugsuG2FpPnDzSGZdmxI/+SWmeXIONL0JE3tZFJrB 5GjkP8amOcrgshRvm5AVx+ipYOyMb8xAxBnTs= Message-ID: Date: Wed, 22 Oct 2008 03:15:53 -0400 From: "Jacques Le Normand" To: lablgtk at yquem.inria.fr MIME-Version: 1.0 Subject: [Lablgtk] clearing widgets from a container, possible memory leak Content-Type: multipart/mixed; boundary="===============1674091265==" Mime-version: 1.0 --===============1674091265== Content-Type: multipart/alternative; boundary="----=_Part_10174_8275359.1224659753968" ------=_Part_10174_8275359.1224659753968 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline Hello lablgtk, this is a small follow-up to the memory question I had earlier. The difference is that I have a test case which increases its memory usage as time goes on. Furthermore, it prints the memory usage 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_10174_8275359.1224659753968 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline Hello lablgtk,
this is a small follow-up to the memory question I had earlier. The difference is that I have a test case which increases its memory usage as time goes on. Furthermore, it prints the memory usage


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_10174_8275359.1224659753968-- --===============1674091265== 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 --===============1674091265==--