W
Why Tea
With respect to the lifetime of an application, my understanding
is that all data on the stack will be released, but data allocated
on the heap will remain unless manually freed. I believe this is
the same between C and C++.
But I read about this statement about C++ object "The lifetime
of a heap allocated object is only limited by the lifetime of the
application." at http://www-numi.fnal.gov/offline_software/srt_public_context/WebDocs/Companion/glossary/heap.html
Does it imply there is some kind of garbage collection, or is this
how C++ works?
This is what Stroustroup says in his book:
An object created by n e w exists until it is explicitly destroyed
by delete . Then, the space it occupied can be reused by new.
A C++ implementation does not guarantee the presence of a
‘‘garbage collector’’ that looks out for unreferenced objects and
makes them available to n e w for reuse. Consequently, I will
assume that objects created by n e w are manually freed using
delete . If a garbage collector is present, the deletes can be
omitted in most cases.
I would like to hear some expert comments on this.
/Why Tea
is that all data on the stack will be released, but data allocated
on the heap will remain unless manually freed. I believe this is
the same between C and C++.
But I read about this statement about C++ object "The lifetime
of a heap allocated object is only limited by the lifetime of the
application." at http://www-numi.fnal.gov/offline_software/srt_public_context/WebDocs/Companion/glossary/heap.html
Does it imply there is some kind of garbage collection, or is this
how C++ works?
This is what Stroustroup says in his book:
An object created by n e w exists until it is explicitly destroyed
by delete . Then, the space it occupied can be reused by new.
A C++ implementation does not guarantee the presence of a
‘‘garbage collector’’ that looks out for unreferenced objects and
makes them available to n e w for reuse. Consequently, I will
assume that objects created by n e w are manually freed using
delete . If a garbage collector is present, the deletes can be
omitted in most cases.
I would like to hear some expert comments on this.
/Why Tea