[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Are delete and delete[] equivalent?
From: |
Paul Pluzhnikov |
Subject: |
Re: Are delete and delete[] equivalent? |
Date: |
Mon, 10 Apr 2006 22:13:50 -0700 |
User-agent: |
Gnus/5.1006 (Gnus v5.10.6) XEmacs/21.4 (Jumbo Shrimp, linux) |
"Aj" <aj.lavin@gmail.com> writes:
> What would be helpful is if someone with knowledge of g++ internals
> could point to the code that answers the question one way or the other.
I don't know 'gcc' internals that well, but you do realize that
'delete[]' calls dtors for all objects, where 'delete' only calls dtor
for the first object.
So, if you 'delete pChar;' where 'delete [] pChar;' was intended,
you are pretty safe (where 'pChar' is of type 'char *', or any
other type with no, or trivial destructor).
But 'delete pStdString' instead of 'delete [] pStdString;' (where
pStdString is of type 'std::string *'), and you'll leak memory like
a sieve.
Cheers,
--
In order to understand recursion you must first understand recursion.
Remove /-nsp/ for email.