If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register or Login
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

An unnecessary test. There is no need to test for NULL if you're calling delete. Calling delete on a NULL pointer results in no operation being performed.

Heap Object created on the stack...

It doesn't matter where the heap object is created (whatever that means). If you call "new", then it's your responsibility to call delete, unless you wrap the call to "new" in a smart pointer, as laserlight pointed out. Getting involved in whether a heap object is created here or there misses the point.

Re: Heap object created on the stack isn't cleaned up properly

From Paul McKenzie:

An unnecessary test. There is no need to test for NULL if you're calling delete.

Quite true! What fools some programmers into thinking otherwise is that the C Run Time will sometimes check the integrity of the heap in a debug build on calls to delete (or at least it used to in earlier versions of Visual Studio). If the heap is corrupted those versions put up an error box and halted the program.

I worked with a programmer once who insisted deleting a NULL pointer wasn't generally safe, but it was because this was happening to him at a point where he was calling delete on a pointer that happened to be NULL. It seems people assume if they get the detection on deletion of a non-NULL pointer, something is wrong with their program, but they won't reach that same conclusion if they are deleting NULL.

Apparently there are quite a few people out there who've been conditioned to wrap their deletes, perhaps because of this. (?)