[Gtk-sharp-list] widget destruction

Mike Kestner mkestner at gmail.com
Mon Mar 7 20:07:05 EST 2011


You should only need to call Destroy on the widget you are removing.
 Destroying AFTER Dispose would be bad.  Dispose releases Gtk#'s reference
to the object and so Destroying after Dispose is bad practice.  Dispose says
you are done with an object.  Calling another method on it is not supported.


If you have a sample that leaks Destroyed Gtk# objects, feel free to open a
bug.  But I'd appreciate that it be confirmed with Heap Profiling tools
before I spend time on it, because I seriously doubt it does leak.  This is
well tested code, and has been verified with profiling in the past.

Mike

On Mon, Mar 7, 2011 at 1:15 AM, huseyin cakir <huseyin.cakir35 at gmail.com>wrote:

> *Hi, we have memory problems in using gtk# in mono 2.8 so we started to
> use a method that includes dispose-destory of all objects.
>
> I mean we use one window widget and change fixed widget in it to use memory
> effectively and dispose destroy all widgets inside it(for example button
> widget).
>
> but it still increases memory usage in time.
>
> Are there any other usages for less memory usage? Thank you.
> *
> *for example:*
>
> to navigate between two pages without memory consumption we use a method
> like below:
>
> fixed A fixed B
> ---------------------------
> window A
>
> add fixed A in window A with other widgets like button widget
>
> remove fixed a
>
> dispose destroy  fixed A with its children
>
> and add fixed B
>
> *
> -----------------------------------------------------------------------------------
> Page 1:*
>
> using System;
> using Gtk;
>
> namespace test
> {
>     class  Page1 : Fixed
>     {
>
>         Button btn1;
>         Image img1;
>         Gdk.Pixbuf px1;
>
>
>         public  Page1()
>         {
>
>             btn1=new Button("go Page2");
>             px1=new Gdk.Pixbuf("4991.gif");
>             img1=new Image(px1);
>             btn1.Clicked+= new EventHandler(btn1_Clicked);
>             this.Put(btn1,10,10);
>             this.Put(img1,10,50);
>
>
>         }
>
>         void btn1_Clicked(object sender, EventArgs e)
>         {
>             freeItems();
>             Page2 pg2=new Page2();
>             Test.win.Add(pg2);
>             Test.win.ShowAll();
>
>         }
>
>
>         void freeItems()
>         {
>             px1.Dispose();
>             img1.Dispose();
>             img1.Destroy();
>             btn1.Dispose();
>             btn1.Destroy();
>             Test.win.Remove(this);
>             this.Dispose();
>             this.Destroy();
>
>
>         }
>
>     }
> }
>
> *
> -----------------------------------------------------------------------------------
> Page 2:*
> using System;
> using Gtk;
>
> namespace test
> {
>
>     class  Page2 : Fixed
>     {
>
>         Button btn1;
>         Image img1;
>         Gdk.Pixbuf px1;
>
>         public  Page2()
>         {
>             btn1=new Button("go back page 1");
>             px1=new Gdk.Pixbuf("4991.gif");
>             img1=new Image(px1);
>
>             btn1.Clicked+= new EventHandler(btn1_Clicked);
>
>             this.Put(btn1,10,10);
>             this.Put(img1,10,50);
>
>         }
>
>         void btn1_Clicked(object sender, EventArgs e)
>         {
>             freeItems();
>             Page1 pg1=new Page1();
>             Test.win.Add(pg1);
>             Test.win.ShowAll();
>         }
>
>         void freeItems()
>         {
>             px1.Dispose();
>             img1.Dispose();
>             img1.Destroy();
>             btn1.Dispose();
>             btn1.Destroy();
>             Test.win.Remove(this);
>             this.Dispose();
>             this.Destroy();
> _______________________________________________
> Gtk-sharp-list maillist  -  Gtk-sharp-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/gtk-sharp-list
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/gtk-sharp-list/attachments/20110307/92be4c1a/attachment.html 


More information about the Gtk-sharp-list mailing list