QQ登录

只需一步,快速开始

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 2223|回复: 4

Gtk窗口占用内存的释放

[复制链接]
发表于 2010-12-28 16:30:09 | 显示全部楼层 |阅读模式
各位大侠们,小弟请教一个问题。
    我在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_();
}
 楼主| 发表于 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/g ... ory-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一个对象之后可能内存不会被释放
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

GMT+8, 2024-4-26 20:38 , Processed in 0.056341 second(s), 15 queries .

© 2021 Powered by Discuz! X3.5.

快速回复 返回顶部 返回列表