Defining a custom *constructor* (not initializer!)

Mehrdad wfunction at hotmail.com
Sat May 12 11:30:07 PDT 2012


On Saturday, 12 May 2012 at 15:57:37 UTC, John Chapman wrote:
>> Yup, they do what C# does with the constructor: they put make 
>> a *separate* function, createHandle(), used to create the 
>> control.
>>
>> And they simply *don't* tie the destructor to DestroyWindow(); 
>> instead, they just assume the user will call dispose().>
>> So in other words, they just ignored the entire problem with 
>> the lifetimes, and hoped ("required"?) that the user will call 
>> dispose().
>
> Actually, in WinForms, closing the application's main Form
> triggers its Dispose method, which disposes of child Controls 
> too.

Yes, that's not a WinForms thing -- when you close a window, it's 
trivial to have  DestroyWindow() get called too.

The trouble is that you can't rely on this to avoid handle leaks 
-- for example, message-only windows are invisible, so their 
handles can get leaked and they can never be closed.


More information about the Digitalmars-d mailing list