I am using C++ to create a program using GTK+ and glade. I am concerned about the memory management of the objects that the glade creates. For example, I create a glade file consisting of a window, a button and two entry fields. Then in my C++ code I create an object from that file and get a pointer to that window. My question is, do I have to safely deallocate the window object when I am done? If not, why do I not have to? Below is a sample of my code…
#include <gtkmm.h>
#include "MattWindow.h"
#include <iostream>
using namespace std;
void buttonpush();
int main(int argc, char* argv[])
{
//This line initializes the GTK+ system
Gtk::Main kit(argc,argv);
//Declare a pointer to a window
Gtk::Window* window = 0;
try
{
//Load the glade file
Glib::RefPtr<Gtk::Builder> builder = Gtk::Builder::create_from_file("layout.glade");
Assign window to point to the window object
builder->get_widget("window1",window);
window->show();
}
catch(Gtk::BuilderError& e)
{
cout<<e.what();
}
//Start everything up
Gtk::Main::run();
//Who destroys the object that window is currently pointing to?
return 0;
}
void buttonpush()
{
}
From the GTK+ reference manual:
To answer your question: yes, you should manually destroy the window when you’re done with it.