Re: Hiding window.



Hi, I'm pretty new to GTK and I'm starting with the Glade ade, I'm looking 
at the GTK tutorial and I can't find out some function that hide a window 
and free the memory used by that one.

gtk_widget_destroy(). Of course you need to pass a pointer to
your widget; if you don't have one you can use Glade's
lookup_widget() helper function.

Can I destroy a window?

Yes, with the function mentioned above. Note that "hiding" a
window is a different thing, but "hide a window and free the
memory used by that one" amounts to destroying it.

what does the gtk_widget_ref();?

It creates a new reference to the widget. A reference is just a
pointer except that the widget keeps track of how many
references to it exist.

Imagine a movie theatre in which a really bad film (the widget)
is playing. Each person going in increases the reference count by
one. Because the film is so bad, people soon start leaving, each
one decreasing the ref count. Once the last person leaves, the
reference count drops to zero, and you can stop the projector.
You never need to check inside the actual theatre as long as you
watch the door. That's how reference counting works: it ensures
that if a ressource (i.e., a widget or a film) isn't destroyed
prematurely but just at the instant nobody needs it any more. Of
course if someone walks out the back door you might keep playing
the film for an empty theatre, waisting time and electricity. The
programming equivalent to this is a "memory leak" and should be
avoided by unreferencing objects properly.

--Daniel




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]