do you ever found memory leak with STL?

R

rokia

I found many people encounter this problem.

and someone say that it's STL strategy.

but I dont know when will it release those memory.

BoundCheck report there are many memory leak when I use vector to push_back
thousands class.

any advice?

thanks .
 
J

John Harrison

I found many people encounter this problem.

and someone say that it's STL strategy.

but I dont know when will it release those memory.

BoundCheck report there are many memory leak when I use vector to
push_back
thousands class.

any advice?

Post the code that you say is leaking memory. And specify which compiler
you are using. Then we might be able to tell you whether the leak is real
or not.

I recall that BoundsChecker reports non-existant memory leaks with the STL
that comes with VC++ 6. But equally you could have made a mistake and
BoundsChecker is reporting genuine memory leaks.

Track the number of times that constructors and destructors are called for
you class. Obviously these totals should be the same, but don't forget to
include the copy cosntructors if you do this.

john
 
C

Chris Theis

John Harrison said:
On Mon, 26 Jul 2004 14:52:03 +0800, rokia <[email protected]> [SNIP]
Track the number of times that constructors and destructors are called for
you class. Obviously these totals should be the same, but don't forget to
include the copy cosntructors if you do this.

To the OP:

And if you need to do this probably a couple of times then you might think
about using a generic tracer class for this purpose.

Chris
 
G

grahamo

There shouldn't be memory leaks in there but that doesn't mean that
you cannot code apps that have memory leaks. e.g. newing objects and
putting pointers to those objects into the container.....the container
won't clean up the memory for you.

That said, don't go using auto_ptrs with containers as you'll be in
for a surprise.


If you post the code here then we could take a look.


cheers

G
 
G

Gernot Frisch

rokia said:
I found many people encounter this problem.

and someone say that it's STL strategy.

but I dont know when will it release those memory.

BoundCheck report there are many memory leak when I use vector to push_back
thousands class.

any advice?

Yes. Sure. You're using a pointer to an element inside the vector. Now
you push/pop/remove any element and whoppa - the pointer does not
point to an element anymore, since the STL container re-allocated the
objects. Now you use any member of that object and see funny errors...
Just a thought... Post code if you're not sure.
-Gernot
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top