[prev in list] [next in list] [prev in thread] [next in thread] 

List:       gtkmm
Subject:    Re: Good style for memory management?
From:       "Milosz Derezynski" <internalerror () gmail ! com>
Date:       2007-03-19 8:51:27
Message-ID: b62edd9c0703190151l7cd38642lf3ebd901830087d2 () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


On 3/18/07, Paul Davis <pjdavis@engineering.uiowa.edu> wrote:

idea is make construction a two step process.  This way the destructor
> will always be called and always free resouces. I believe this is the
> wrong answer.


Well, what you said, and additionally if intialization and resource
allocation in the ctor isn't complete, but the
dtor gets called anyway, you'll sort of end up with comparable problems like
checking what actually *has* been
allocated and what has to be released again; obviously this isn't standard
procedure for writing a dtor (i for one
always am writing dtors assuming that the object has been fully
constructed), so basically in all my ctors i do the
same what i think we both suggested to Paul, namely making sure that
something doesn't throw and if it does, catch
it in the ctor, make sure we free all resources, and then there's always
just throw; to let the caller know about the exception
if it's neccessary for it to know.

Well long speech point being, it does not even matter whether it is *inside*
the ctor or outside of it, but Paul's original example
with creating a new dynamically instance, initializing it with whatever in
between, and then only adding it to a parent container *is really bad*.

I wouldn't do that with gtkmm, nor gtk+ for that matter to the extent it's
possible there (no exceptions but you can still always forget to add
the widget to a container). Gtk+ basically imposes on you to add it to a
container to manage the widget itself so this should be done ASAP
after construction (e.g., now to the "original" Paul: Design your widget so
it can remain hidden until it has been setup trough the ::init() method, but
add it to the container already before calling your ::init() )

Milosz

[Attachment #5 (text/html)]

<br><br><div><span class="gmail_quote">On 3/18/07, <b class="gmail_sendername">Paul \
Davis</b> &lt;<a href="mailto:pjdavis@engineering.uiowa.edu">pjdavis@engineering.uiowa.edu</a>&gt; \
wrote:<br><br></span><blockquote class="gmail_quote" style="border-left: 1px solid \
rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"> idea is make \
construction a two step process.&nbsp;&nbsp;This way the destructor<br>will always be \
called and always free resouces. I believe this is the<br>wrong \
answer.</blockquote><div><br></div></div>Well, what you said, and additionally if \
intialization and resource allocation in the ctor isn&#39;t complete, but the \
<br>dtor gets called anyway, you&#39;ll sort of end up with comparable problems like \
checking what actually *has* been<br>allocated and what has to be released again; \
obviously this isn&#39;t standard procedure for writing a dtor (i for one <br>always \
am writing dtors assuming that the object has been fully constructed), so basically \
in all my ctors i do the<br>same what i think we both suggested to Paul, namely \
making sure that something doesn&#39;t throw and if it does, catch <br>it in the \
ctor, make sure we free all resources, and then there&#39;s always just throw; to let \
the caller know about the exception<br>if it&#39;s neccessary for it to \
know.<br><br>Well long speech point being, it does not even matter whether it is \
*inside* the ctor or outside of it, but Paul&#39;s original example <br>with creating \
a new dynamically instance, initializing it with whatever in between, and then only \
adding it to a parent container *is really bad*.<br><br>I wouldn&#39;t do that with \
gtkmm, nor gtk+ for that matter to the extent it&#39;s possible there (no exceptions \
but you can still always forget to add <br>the widget to a container). Gtk+ basically \
imposes on you to add it to a container to manage the widget itself so this should be \
done ASAP<br>after construction (e.g., now to the &quot;original&quot; Paul: Design \
your widget so it can remain hidden until it has been setup trough the ::init() \
method, but add it to the container already before calling your ::init() ) \
<br><br>Milosz<br>



_______________________________________________
gtkmm-list mailing list
gtkmm-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtkmm-list


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic