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

  • SEARCH
  • Home
  • 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 7832387
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T12:11:49+00:00 2026-06-02T12:11:49+00:00

I have a notebook that contains pages with tabs that have close buttons in

  • 0

I have a notebook that contains pages with tabs that have close buttons in them. When you click on the button, the page in that tab is then removed from the notebook( closed).
The problem is that when the tab closes, the memory is never freed, because there seems to be something still referencing the destroyed page.

Here is some sample code for my notebook:

notebook = gtk.Notebook
def create_tab():
    page = gtk.Label( "THis is a page")
    page.show()
    tab = gtk.HBox()#The custom tab-label widget
    tab_label = gtk.Label( "Tab")
    tab_label.show()
    tab.pack_start( tab_label)
    tab_close = gtk.Button()
    tab_close.set_image(gtk.image_new_from_stock(gtk.STOCK_CLOSE, gtk.ICON_SIZE_MENU))
    tab_close.connect( 'clicked', destroy_tab, page )
    tab_close.show()
    tab.pack_end( tab_close)
    tab.show()

    notebook.append_page(page, tab)
def destroy_tab( widget, data=None):
    page_num = notebook.page_num( data )
    notebook.remove_page( page_num )
    data.destroy()

The create_tab function is a callback added to a button’s clicked signal, so I can add as many pages to the notebook as I’d like. But when the page is removed from the notebook, through the destroy_tab callback, the page is successfully removed from the notebook, but the memory is never freed.

This link outlines the same problem I’m having. And one thing it suggests is that there is still a reference to the page through the custom widget set as the tab_label. I’ve also tried destroying the custom widget, even recursively destroying all of its children but still can’t seem to figure out what is still referencing this page to keep it in memory. What could be the problem?

  • 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-02T12:11:51+00:00Added an answer on June 2, 2026 at 12:11 pm

    I managed to figure out, through gc.getreferrers() that there was a circular reference
    between the close button and the page that it was closing. Through further testing, I found out that it’s of no fault of my own, but in the way that a GtkNotebook seems to link the two when they’re added to the notebook. I did manage to get rid of that circular reference simply
    by creating a custom button that holds a reference to the widget itself, so then, when the button is destroyed, that widget reference is set to None and that seems to successfully get rid of the reference.
    However, this still doesn’t seem to clear up the memory behind the page after it is closed.

    Here’s the revamped code:

    class CloseButton(gtk.Button):
        def __init__(self, widget):
            gtk.Button.__init__(self)
            self.widget_ref = widget#Pass the widget reference to this button
            #Initialize the button here...
            self.connect( 'destroy', self.on_destroy )
        def on_destroy( self, widget ):
            self.widget_ref = None#Destroy the reference to the widget
    

    And then, in the code you would use the button like so:

    notebook = gtk.Notebook
    def create_tab():
        page = gtk.Label( "THis is a page")
        page.show()
        tab = gtk.HBox()#The custom tab-label widget
        tab_label = gtk.Label( "Tab")
        tab_label.show()
        tab.pack_start( tab_label)
        tab_close = CloseButton(page)#pass a reference to page
    
        tab_close.connect( 'clicked', destroy_tab )
        tab_close.show()
        tab.pack_end( tab_close)
        tab.show()
    
        notebook.append_page(page, tab)
    
    def destroy_tab( widget, data=None):
        page_num = notebook.page_num( widget.widget_ref )
        notebook.remove_page( page_num )
        widget.destroy()
    

    And that does the trick! The reference disappears when the destroy method is called on the button

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

Sidebar

Related Questions

When using a notebook and I have remarked that I cannot enter numerical character
I have a GtkNotebook that will contain at the very least, one permanent tab,
I have modified my notebook's stylesheet to include a StyleData[Todo] that inherits from StyleData[Item]
Using Ipython notebook and the pandas module, I have a bit of code that
I have a situation where say, a Notebook stores Pages . At first, I
I have a navigation that's supposed to imitate the look of classical notebook with
Recently I have purchased a notebook that came with Windows Home Basic (that don't
I'm trying to create new GTK Notebook tabs that contain both a name (as
I'm working on an app that's a bit like a notebook of typed pages.
I'm trying to scrape only article text from web pages. I have discovered that

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.