|
From: Ioannis V. <no...@ho...> - 2002-09-01 20:13:38
|
Memory leak is when you allocate memory dynamically (on the free store) =
and you do not free it. You can avoid memory leak by using the standard =
containers instead of allocating and deallocating memory dynamically.
=20
=20
For example
=20
=20
Instead of writing:
=20
class A
{
int *p;
// ...
public:
A(const int x) { p=3Dnew int [x]; }
~A() { delete[] p; }
// ...
};
=20
=20
write
=20
class A
{
vector v;
// ...
public:=20
A(const int x):v(x) {}
// ...
=20
=20
Instead of writing
=20
=20
int *something()
{
//...=20
int *p=3Dnew int[20];
//...
=20
return p;
}
=20
=20
write
=20
void something(vector<int>&v)
{
// store everything in v;
}
=20
=20
When the container reaches the end of its scope, it clears itself =
automatically.
=20
=20
=20
=20
Ioannis
* Ioannis Vranos
* Programming pages: http://www.noicys.cjb.net =
<http://www.noicys.cjb.net/>=20
* Alternative URL: http://run.to/noicys
-----Original Message-----
From: dev...@li... =
[mailto:dev...@li...] On Behalf Of Stein =
Nyg=CE=B5rd
Sent: Sunday, September 01, 2002 10:09 PM
To: Met...@ao...; dev...@li...
Subject: Re: [Dev-C++] q??
How is it possible to be sure if your program is not leaking any memory? =
Is there anyway to test a program for leaks?
=20
thanks
Stein Nyg=C3=A5rd - http://steinware.dk
lapido, ergo sum
----- Original Message -----=20
From: Met...@ao...=20
To: dev...@li...=20
Sent: Sunday, September 01, 2002 8:22 PM
Subject: Re: [Dev-C++] q??
Hi Senem=20
Zodiaq is joking with memory leaks...=20
In fact, that means that the memory is not handled the way it should be =
inside a program.=20
It can be a single pointer allocated twice, allocated memory not =
freed...=20
Some proggys are very leaky. Like AOL for example. I wonder if the =
people that coded that piece of sh** ever heard of the "free" =
instruction in C standard library.=20
Kind regards=20
--=20
Seb=20
|