Click here to Skip to main content
15,922,894 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Something to understand to new and delete!? Pin
Zac Howland17-Nov-06 5:31
Zac Howland17-Nov-06 5:31 
GeneralRe: Something to understand to new and delete!? Pin
toxcct17-Nov-06 8:37
toxcct17-Nov-06 8:37 
AnswerRe: Something to understand to new and delete!? Pin
Roger Stoltz17-Nov-06 2:28
Roger Stoltz17-Nov-06 2:28 
GeneralRe: Something to understand to new and delete!? Pin
Zac Howland17-Nov-06 5:34
Zac Howland17-Nov-06 5:34 
GeneralRe: Something to understand to new and delete!? Pin
Roger Stoltz17-Nov-06 5:37
Roger Stoltz17-Nov-06 5:37 
GeneralRe: Something to understand to new and delete!? Pin
Zac Howland17-Nov-06 5:55
Zac Howland17-Nov-06 5:55 
GeneralRe: Something to understand to new and delete!? Pin
David Crow17-Nov-06 6:30
David Crow17-Nov-06 6:30 
AnswerRe: Something to understand to new and delete!? Pin
Viorel.17-Nov-06 2:35
Viorel.17-Nov-06 2:35 
In my opinion, in the second case:
pMyClass = NULL;
delete pMyClass;

you will not receive any run-time error, since deleting of null pointer is not an error (delete simply does nothing).

But in this case your object, allocated with new, will remain unused in the heap memory, producing "memory leak".

Therefore, the correct way is:
delete pMyClass;
pMyClass = NULL;  // not needed if pMyClass is not more used

If you are familiar with STL, you can also consider this approach:
std::auto_ptr< CMyClass > pMyClass(new CMyClass);

I this case the de-allocation will be performed automatically.

I hope this helps.
GeneralRe: Something to understand to new and delete!? Pin
bosfan17-Nov-06 2:56
bosfan17-Nov-06 2:56 
GeneralRe: Something to understand to new and delete!? Pin
Zac Howland17-Nov-06 5:36
Zac Howland17-Nov-06 5:36 
AnswerRe: Something to understand to new and delete!? Pin
Zac Howland17-Nov-06 5:26
Zac Howland17-Nov-06 5:26 
QuestionOwn Messages Pin
baerten17-Nov-06 1:20
baerten17-Nov-06 1:20 
AnswerRe: Own Messages Pin
Roger Stoltz17-Nov-06 2:02
Roger Stoltz17-Nov-06 2:02 
GeneralRe: Own Messages Pin
baerten17-Nov-06 3:25
baerten17-Nov-06 3:25 
GeneralRe: Own Messages Pin
Roger Stoltz17-Nov-06 4:21
Roger Stoltz17-Nov-06 4:21 
AnswerRe: Own Messages [modified] Pin
Tony Hill17-Nov-06 2:03
professionalTony Hill17-Nov-06 2:03 
GeneralRe: Own Messages Pin
baerten17-Nov-06 3:19
baerten17-Nov-06 3:19 
AnswerRe: Own Messages Pin
Viorel.17-Nov-06 3:29
Viorel.17-Nov-06 3:29 
GeneralRe: Own Messages Pin
baerten17-Nov-06 4:03
baerten17-Nov-06 4:03 
AnswerRe: Own Messages Pin
S Douglas18-Nov-06 23:24
professionalS Douglas18-Nov-06 23:24 
QuestionShowing log messages from threads into a common ListBox Pin
Cyber Friend17-Nov-06 0:18
Cyber Friend17-Nov-06 0:18 
AnswerRe: Showing log messages from threads into a common ListBox Pin
Rage17-Nov-06 0:27
professionalRage17-Nov-06 0:27 
GeneralRe: Showing log messages from threads into a common ListBox Pin
Cedric Moonen17-Nov-06 1:32
Cedric Moonen17-Nov-06 1:32 
GeneralRe: Showing log messages from threads into a common ListBox Pin
Rage17-Nov-06 4:15
professionalRage17-Nov-06 4:15 
AnswerRe: Showing log messages from threads into a common ListBox Pin
Waldermort17-Nov-06 0:32
Waldermort17-Nov-06 0:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.