[Gtk-sharp-list] widget destruction

huseyin cakir huseyin.cakir35 at gmail.com
Mon Mar 7 02:15:04 EST 2011


*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();
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/gtk-sharp-list/attachments/20110307/5bbbbeb5/attachment.html 


More information about the Gtk-sharp-list mailing list