Re: Memory leak
Alex wrote:
Is the program still leak memory?
int main()
{
Type *atype = new Type();
// use the atype
....
ruturn 0;
}
Define what you mean by "leak memory".
The program never call delete but terminate itself. Does the
kernel will close all the open file descriptors for the
process and releases all the memory that it was used?
Maybe. In the case of Windows or Posix compliant systems (and
Linux), yes.
But that's not what most people understand by a memory leak. My
singletons, for example, normally allocate memory that is never
freed, and the C++ standard almost requires this behavior of the
standard stream objects (which have a dynamically allocated
buffer, but are never destructed). In most cases, a "memory
leak" means a repeated action---most programs run for an
indeterminate amount of time, and if the longer the program
runs, the more memory it uses, then there is a good chance that
it won't be able to run long enough.
Typuically, such acceptable "leaks" are limited to static
objects (since the number of these cannot increase as the
program runs). It's considered fairly bad style to just abandon
memory in a function, even if, as is the case of main, you can
be sure that the function is only called once.
--
James Kanze (Gabi Software) email: james.kanze@gmail.com
Conseils en informatique orient?e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S?mard, 78210 St.-Cyr-l'?cole, France, +33 (0)1 30 23 00 34
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]