On 24/11/2016 16:03, Paavo Helde wrote:
> On 24.11.2016 14:35, JiiPee wrote:
>> On 24/11/2016 03:57, Jerry Stuckle wrote:
>>> But MFC doesn't use unique_ptr, so someone has to delete it or you have
>>> a memory leak. And after the return from OnNcDestroy() the object
>>> should never be referenced again (and isn't in MFC).
>>
>>
>> but even if it is not a smart pointer, the user must still *know* that
>> the function will destroy it. Is there a risk here and confusion that if
>
> Confusion is the middle name of MFC! :-)
hehe. Well, I still like it (even if its not perfect/pretty). Remember,
i have lived my whole programming life with it!! And I dont like
divorces, hehe. People take divorces too easily.. I am a faithfull man :).
>
>> the user forgots that its self deleted? How does the user remember that
>> in this occasion the object will be self-destroyed?
>
> What do you mean by "user"?
the one who uses that Dialog. The programmer who writes code to use that
dialog.
> If you mean the programmer, then he is supposed to follow the
> documentation. If it is the calling code, then this calling code is
> MFC which *assumes* that dialog will be dead after OnNcDestroy().
but the question is that do we delete the dialog object inside the
dialog class (at OnNcDestroy call) or from the class where it is
created. But seems like Microsoft supports this... below:
> This function should not be called explicitly from elsewhere than MFC.
>
> Besides, MSDN documentation says that 'delete this;' should be put
> into virtual PostNcDestroy() override which is called from the default
> implementation of OnNcDestroy(), so whoever placed it directly in
> OnNcDestroy()
Good catch. Oh, now i get it. I was capturing the message directly, but
I should use the virtual call. Ok, but online many people seem to use
directly OnNcDestroy(); message function.
but the confusion I mentioned is more like with the delete this;
>
>
>