xc870517 发表于 2010-12-28 16:30:09

Gtk窗口占用内存的释放

各位大侠们,小弟请教一个问题。
    我在FC4下使用Gtkmm编程,用Glade做界面,我现在的程序是当界面显示处来后,就会一直存在于内存中,直到程序退出,这样程序会占用很大的内存,因此我希望在退出界面的时候,同时释放掉这个界面所占用的内存,等到下次要再进入的时候重新创建新的。我使用hide()方法后,界面只是隐藏掉,内存并没有变化,我调用destroy_()方法,也只对部分窗口有效,对有些窗口,内存仍然没有变化,我是一个初学者,希望各位大侠们给点指点。

下面是我的部分代码:
......

MyForm* MyForm::Create()
{
    static Glib::RefPtr<Gnome::Glade::Xml> XmlGlade;
    //Glib::RefPtr<Gnome::Glade::Xml> XmlGlade;//退出时使用destroy_()时用这句
    if(!XmlGlade)
    {
          std::string gladeName = "myform.glade";
          try
         {
            XmlGlade = Gnome::Glade::Xml::create(gladeName.c_str());
         }
         catch(const Gnome::Glade::XmlError& ex)
      {
             std::cerr << ex.what() << std::endl;
             return false;
      }
   }
   MyForm*form = NULL;
   XmlGlade->get_widget_derived("window", form);
   return form;
}

void MyForm::Exit()
{
      .....

      hide();
      //destroy_();
}

xc870517 发表于 2010-12-29 19:48:15

怎么没有人啊!给点力啊!

路西法 发表于 2011-1-10 14:20:37

g_free()呢?我对gtkmm不熟,gtk/gllib还行点……

默难 发表于 2011-2-13 22:17:30

new/delete
http://library.gnome.org/devel/gtkmm-tutorial/2.21/sec-memory-widgets.html.en

gtkmm allows the programmer to control the lifetime (that is, the construction and destruction) of any widget in the same manner as any other C++ object. This flexibility allows you to use new and delete to create and destroy objects dynamically or to use regular class members (that are destroyed automatically when the class is destroyed) or to use local instances (that are destroyed when the instance goes out of scope). This flexibility is not present in some C++ GUI toolkits, which restrict the programmer to only a subset of C++'s memory management features.

默难 发表于 2011-2-13 22:19:01

再说一句:
我不知到gtkmm有没有内存池的设计,如果有的话,delete一个对象之后可能内存不会被释放
页: [1]
查看完整版本: Gtk窗口占用内存的释放