Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > do you ever found memory leak with STL?

Reply
Thread Tools

do you ever found memory leak with STL?

 
 
rokia
Guest
Posts: n/a
 
      07-26-2004

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 .


 
Reply With Quote
 
 
 
 
John Harrison
Guest
Posts: n/a
 
      07-26-2004
On Mon, 26 Jul 2004 14:52:03 +0800, rokia <(E-Mail Removed)>
wrote:

>
> 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
 
Reply With Quote
 
 
 
 
Chris Theis
Guest
Posts: n/a
 
      07-26-2004

"John Harrison" <(E-Mail Removed)> schrieb im Newsbeitrag
newspsbqgkzmv212331@andronicus...
> On Mon, 26 Jul 2004 14:52:03 +0800, rokia <(E-Mail Removed)>

[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


 
Reply With Quote
 
grahamo
Guest
Posts: n/a
 
      07-26-2004
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

> 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 .

 
Reply With Quote
 
Gernot Frisch
Guest
Posts: n/a
 
      07-26-2004

"rokia" <(E-Mail Removed)> schrieb im Newsbeitrag
news:ce29mq$1f2m$(E-Mail Removed)99.com...
>
> 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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Memory leak even after deleting memory pointers from vector cham C++ 5 09-25-2008 10:30 AM
Leak or no leak ?? Richard Heathfield C Programming 4 07-10-2006 11:37 AM
Dynamic memory allocation and memory leak... s.subbarayan C Programming 10 03-22-2005 02:48 PM
Memory leak??? (top reporting high memory usage under Solaris) Mark Probert Ruby 4 02-09-2005 06:13 PM
don't you ever, don't you ever, lower yourself, forgetting all your standards Jason ASP .Net Web Controls 0 07-06-2004 12:50 PM



Advertisments