Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8494185
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T23:13:49+00:00 2026-06-10T23:13:49+00:00

I am using C++ to create a program using GTK+ and glade. I am

  • 0

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()
{

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T23:13:50+00:00Added an answer on June 10, 2026 at 11:13 pm

    From the GTK+ reference manual:

    A GtkBuilder holds a reference to all objects that it has constructed
    and drops these references when it is finalized. This finalization can
    cause the destruction of non-widget objects or widgets which are not
    contained in a toplevel window. For toplevel windows constructed by a
    builder, it is the responsibility of the user to call
    gtk_widget_destroy() to get rid of them and all the widgets they
    contain.

    The functions gtk_builder_get_object() and gtk_builder_get_objects()
    can be used to access the widgets in the interface by the names
    assigned to them inside the UI description. Toplevel windows returned
    by these functions will stay around until the user explicitly destroys
    them with gtk_widget_destroy(). Other widgets will either be part of a
    larger hierarchy constructed by the builder (in which case you should
    not have to worry about their lifecycle), or without a parent, in
    which case they have to be added to some container to make use of
    them. Non-widget objects need to be reffed with g_object_ref() to keep
    them beyond the lifespan of the builder.

    To answer your question: yes, you should manually destroy the window when you’re done with it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to create program that creates a XML schema like below using System.Xml.XmlSchema
Is it possible to create a program using AS3 that would allow the user
Is there a way using JNI and C# code to create a program that
I have some Bruker NMR spectra that i am using to create a program
i have to create a program to login on facebook using example http://code.google.com/p/facebook-java-api/wiki/Examples but
I am trying to create a program that calls another process using CreateProcess. After
I have to create a program that takes an input file of unsorted numbers
In a Python program I have a read-only property that I create using bla
I have been trying to create a program using perl www::Mechanize that will follow
I was trying to create a program that takes arguments by command line, using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.