Fw: [Dev-C++] Memory leak with STL list erase
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Alessandro B. <al...@vi...> - 2004-03-22 20:33:18
|
Yes, I know the containers contains only copies and I made an error in
example code (missing delete temp) but even if I delete the memory
allocated
with new the problem is the same: without delete the program uses 32 M,
using delete the program uses 16 M also after the clear() (but the size()
of
the list is correctly 0).
Other suggestions?
Thanks
Alessandro
> ----- Original Message -----
> From: "Paul Muehlbach" <tr...@gm...>
> To: "Alessandro Bugatti" <al...@vi...>
> Sent: Monday, March 22, 2004 11:56 AM
> Subject: Re: [Dev-C++] Memory leak with STL list erase
>
>
> > STL containers only contain copies of data that is inserted, not the
data
> > itself!
> >
> > cu! traexx
> >
> >
> > > Hi,
> > > I tried to use the STL list in order to insert and erase some element,
> but
> > > if I look to the memory usage of my program it seems when I erase
> elements
> > > the memory occupation it is the same (also if I use clear()).
> > > This code is an example
> > >
> > > #include <iostream>
> > > #include <list>
> > > #include <cstdlib>
> > >
> > > using namespace std;
> > >
> > > class prova
> > > {
> > > public:
> > > int x,y;
> > > prova(int X, int Y):x(X),y(Y){}
> > > };
> > >
> > > int main()
> > > {
> > > list <prova> lista;
> > > for (int i=0;i<1000000;i++){
> > > prova *temp= new prova(rand()%2,i);
> > > lista.push_back(*temp);}
> > > list<prova>::iterator t;
> > > t=lista.begin();
> > > while (t!=lista.end())
> > > {
> > > if (t->x==0)
> > > t=lista.erase(t);
> > > else
> > > t++;
> > > }
> > > lista.clear();
> > > system("PAUSE");
> > > return 0;
> > > }
> > >
> > > Some suggestions?
> > > Thanks in advance:
> > > Alessandro
> >
> > --
> > +++ NEU bei GMX und erstmalig in Deutschland: TÜV-geprüfter Virenschutz
> +++
> > 100% Virenerkennung nach Wildlist. Infos: http://www.gmx.net/virenschutz
> >
> >
>
|