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 (domain does not match address; no policy for yquem.inria.fr) Delivered-To: lablgtk at yquem.inria.fr DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=math.nagoya-u.ac.jp; h= date:message-id:to:cc:subject:from:in-reply-to:references :mime-version:content-type:content-transfer-encoding; s=alpha; bh=mw0ZJldnIqH/UfO8mbSCQN5TlOI=; b=mQZv0nTJQ5sGPTj74bUu1yfsEbtR VgIVnUNBaLUxHkwg1leTruwilktMHFsFD+K2QatNXGuHVZnCnjXgULlqXdzSnqgF 10P+i5sJm9FdWqeHIl7a/Msv9WilAG3R2ncXjmL+Ta3R3rtzhbLYeAt9+o5kqDK8 OdLeHl6Hi8ZH08k= DomainKey-Signature: a=rsa-sha1; h=Received:Date:Message-Id:To:Cc:Subject:From:In-Reply-To:References:X-Mailer:Mime-Version:Content-Type:Content-Transfer-Encoding; b=ItLqCXIpS9cCXc/mcQYoYkOXaPq0vud3YUemfAObmyH5+lcg1almVj37i3QJ/jWVrZ0hi7r8Nh2pOvh3yh93D+MhhMRq/zK5Yem8BwKx1Z7m/voQhA/9t0GEAudYT4ljWqMoLxeIltxJs3jPVIqLekvEGFeQ7WxtDhE2TZn2Wk0=; c=nofws; d=math.nagoya-u.ac.jp; q=dns; s=alpha Date: Mon, 27 Oct 2008 11:28:28 +0900 (JST) Message-Id: <20081027.112828.78704204.garrigue at math.nagoya-u.ac.jp> To: rathereasy at gmail.com Subject: Re: [Lablgtk] memory leak, destroying widgets From: Jacques Garrigue In-Reply-To: References: Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Cc: lablgtk at yquem.inria.fr From: "Jacques Le Normand" > 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. You should use Gc.full_major, to ensure that all finalizers are called. Note however that, in byte code, a variable referenced in the environment (either function argument or let-definition) cannot be freed until you leave the function. It should be ok to add a Gc.full_major call in your timeout. Jacques > 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 () _______________________________________________ Lablgtk mailing list Lablgtk@yquem.inria.fr http://yquem.inria.fr/cgi-bin/mailman/listinfo/lablgtk