[mythtv] Re: Myth Theme Memory Usage

Joseph A. Caputo jcaputo1 at comcast.net
Thu Dec 9 15:16:09 UTC 2004

On Wednesday 08 December 2004 21:42, Alan Gonzalez wrote:
> > Actually, it's not *guaranteed* to be OK to delete a NULL
> > pointer... though it usually is, it's implementation-defined
> > behavior.  I usually do the following just to be safe:
> >
> >         if (ptr)
> >         {
> >                 delete ptr;
> >                 ptr = NULL;
> >         }
> Really?  The C99 specification states otherwise.   I've been under
> the assumption that this is an old myth that continues to be
> propagated. Have you actually seen something like that happen?  I
> haven't.  I know that GCC, G++ and Microsoft compilers (look at MSDN
> docs on 'delete' operator) check the value of the pointer being sent
> in.
> Found this:
> "C++ guarantees that operator delete checks its argument for
> null-ness. If the argument is 0, the delete expression has no effect.
> In other words, deleting a null pointer is a safe (yet useless)
> operation. There is no need to check the pointer for null-ness before
> passing it to delete:

Well, there you go; I'm dating myself.  :-)

I'm falling back on my pre-C99, pre-ANSI/ISO C++ knowledge... actually, 
most of my formative C++ experience was really not C++ at all, but 
cfront.  At the very least, I know that in at least one version of 
pre-ANSI C++ or possibly cfront, the array delete (delete [] ) operator 
at least was not guaranteed to be NULL-pointer safe.

Ah, well... you learn something every day!


More information about the mythtv-dev mailing list