Hello,

I have the following code in main:-

int _tmain(int argc, _TCHAR* argv[])
{
MyAmi *ptr = 0;
ptr->doIt();
delete ptr; ptr = NULL;
return 0;
}
A colleague of mine tells me that I don't have to do this: -
delete ptr; ptr = NULL;
becasue doIt() is the last thing that will take place by the compiler and ptr will be out of scope when main finishes, similarly to :-

int _tmain(int argc, _TCHAR* argv[])
{
int i = 5;
return 0;
}
i.e. we don't delete i (and ptr is just like any other variable and holding an address of another variable shouldn't make any difference).

However, my experience tells me all pointers need to be deleted before the program finishes. He says that only if there are pointers member variables and thus, the constructor allocates memory using new, then the destructor need to deallocate that memory using delete.

Can you please advise.

Many thanks.