Re: Newbies don't learn C++
On 13/01/2011 19:47, James Kanze wrote:
On Jan 13, 7:24 pm, Leigh Johnston<le...@i42.co.uk> wrote:
On 13/01/2011 18:57, Paavo Helde wrote:
Leigh Johnston<le...@i42.co.uk> wrote in news:wOOdnWqtq-
bmj7LQnZ2dnUVZ8gWdn...@giganews.com:
You are also forgetting that an object
can become unreachable and yet not be a leak (delete this).
In order to 'delete this' the this pointer value must be known to the
executing code so clearly the object is not unreachable. And please don't
start to invent new definitions for "unreachable"!
Following your logic all C++ objects are never unreachable as they all
effectively have a "this" pointer so can never "leak" according to some
people's definition of "leak"; this is absurd.
A C++ object is *not* unreachable when executing a member
function. A this pointer does prevent the memory from becoming
unreachable, but C++ objects don't have this pointers. Only
non-static member functions have this pointers, and then only
when they are actually executing.
I used the word "effectively"; obviously a C++ object does not
*actually* contain a this pointer but the this pointer is available
whilst member functions are being invoked on the associated object. Are
you reverting to troll mode already?
A memory leak can be a *consequence* of an object becoming
unreachable.
One definition of a memory leak is that the object is
unreachable. IMHO, it's not a very useful definition, but some
Java programmers like to use it, in order to claim that memory
leaks are impossible in Java (despite Sun having recognized some
memory leaks as bugs).
A memory leak is programmer provided allocation with no matching
programmer provided deallocation.
That's an even more arbitrary definition, and certainly not
applicable in most cases.
I disagree; Microsoft agree with my definition; appealing to authority I
know *if* you consider Microsoft to be an authority; I am sure that
there are plenty of other respectable sources that agree with my definition.
There is no difference between the following two programs as far as what
the OS (or C/C++ runtime) has to cleanup during program termination
(they both leak):
--
int* leak = new int[4200000];
int main() {}
--
int main() { int* leak = new int[4200000]; }
--
Who says there is?
I am saying there is; I am sure others agree with me just as there are
others who agree with you. Your leaking singleton is a piece of junk
(even if you don't admit it).
/Leigh