[Gtk-sharp-list] widget destruction

Christopher David Howie me at chrishowie.com
Fri Mar 11 19:35:05 EST 2011

 On Wed, 9 Mar 2011 10:54:13 -0500, Nicholas Frechette wrote:
> I disagree strongly with the implicit destruction of managed 
> resources
> through the use of that pattern and the finalizer. Having worked
> extensively on embedded systems where tight control over memory is
> always required, in my experience, it is always better to provide
> tools for programmers to fix bad usage than it is to brush it under
> the rug and do their job for them. The finalizer should be there only
> to warn that memory is leaking and if you must, free that memory, but
> the warning is key so that the code can be fixed. Finalizers add a
> cost that can be very hard to measure.
>  All objects that have managed resources to discard should implement
> Dispose and call base. Destroy should probably call Dispose (and not
> the other way around). Either way, documentation has to state clearly
> which is which and how to properly subclass widgets/other things.

 I lost Lluis' response while doing some maintenance on my email scripts 
 (whoops) but I wanted to suggest a compromise.  For some people it's 
 nice to get warnings when you've "leaked" an object that wraps a native 
 resource, but for others they don't care about that.  Neither approach 
 is necessarily wrong.  I'd support the option of having opt-in or 
 opt-out warnings that you control with a static property on the GObject 
 class.  Then people who are trying to tightly control their memory usage 
 can get warnings when they have failed to do so, and others who are less 
 worried about strict memory usage (for example when writing desktop 
 applications) can let the GC do its magic.

 Chris Howie

 If you correspond with me on a regular basis, please read this 
 document: http://www.chrishowie.com/email-preferences/

 PGP fingerprint: 2B7A B280 8B12 21CC 260A DF65 6FCE 505A CF83 38F5


 This document should be read only by those persons to whom it is 
 addressed.  If you have received this message it was obviously addressed 
 to you and therefore you can read it.

 Additionally, by sending an email to ANY of my addresses or to ANY 
 mailing lists to which I am subscribed, whether intentionally or 
 accidentally, you are agreeing that I am "the intended recipient," and 
 that I may do whatever I wish with the contents of any message received 
 from you, unless a pre-existing agreement prohibits me from so doing.

 This overrides any disclaimer or statement of confidentiality that may 
 be included on your message.

More information about the Gtk-sharp-list mailing list