GNOME Bugzilla – Bug 138248
Book: manage() used before it is explained.
Last modified: 2004-12-22 21:47:04 UTC
I had trouble trying to understand the memory management strategy employed by gtkmm by reading through the docs. I first read the FAQ, and then the 22 chapter tutorial (plus some of the appendices). Here's what I thought was confusing: First, by reading the FAQ (specifically part 4 of question 1.4), I saw the statement that, "As a C++ coder you know that pointers should be avoided where possible." That made me believe that smart pointers would probably be employed... I was reading through the tutorial, and came across tutorial/html/ch04s04.html which used the 'manage' function with no explanation. I had to google to find http://mail.gnome.org/archives/gtkmm-list/2002-October/msg00102.html to start to understand the example (and realize that my initial guess was unfortunately wrong), though this email (and the few others I looked at) didn't quite answer all my questions. Finally, I get to chapter 18 and it answers my questions abou memory management. Perhaps I started thinking about memory management a little bit earlier than others would have, but shouldn't there should at least be a comment back in chapter 4 when manage is used stating that the manage function will be explained in chapter 18? Either that, or remove the references to manage that appear before chapter 18? Also, although chapter 18 answered my memory management questions up to that point, chapter 19 (Glademm and Libglademm) throw another wrench into the works because nothing I can find states whether the user is responsible for deallocating the pointers that are returned from get_widget and get_widget_derived.
So, maybe manage() and RefPtr should be explained in the Basics chapter at the start. You could copy some of the existing text from the "memory management" chapter for that - it should just be a condensed version of that chapter. > nothing I can find states whether the user is responsible for deallocating the pointers > that are returned from get_widget and get_widget_derived. In the case of top-level windows, I have to investigate this a bit. In general, you should not expect to delete what you did not new.
I have added this text to the libglademm chapter: <para><literal>get_widget()</literal> returns child widgets that are manage()ed (see the <link linkend="sec-Memory>Memory Management</link> chapter), so they will be deleted when their parent container is deleted. So, if you get only a child widget from libglademm, instead of a whole window, then you must either put it in a Container or delete it. Windows (such as Dialogs) can not be managed because they have no parent container, so you must delete them at some point.</para> That should take care of that. I leave the other point to you, as suggested.
Is there any chance that you will find time to do that?
I'm sorry for not having responded sooner. Yes, I will find some time to do this. It probably won't be until after Gnome 2.8 is released, though.
I have added a short description of Gtk::manage() to the Basics, Widgets section, with a link to the Memory Management chapter. That should deal with everything. Thanks for pointing this stuff out.
Oops! Sorry for letting everything else get in the way of fixing this and forgetting about it. Thanks for fixing it up, though!