do you ever found memory leak with STL?

Discussion in 'C++' started by rokia, Jul 26, 2004.

  1. rokia

    rokia Guest

    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 .
    rokia, Jul 26, 2004
    #1
    1. Advertising

  2. On Mon, 26 Jul 2004 14:52:03 +0800, rokia <>
    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
    John Harrison, Jul 26, 2004
    #2
    1. Advertising

  3. rokia

    Chris Theis Guest

    "John Harrison" <> schrieb im Newsbeitrag
    news:eek:psbqgkzmv212331@andronicus...
    > On Mon, 26 Jul 2004 14:52:03 +0800, rokia <>

    [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
    Chris Theis, Jul 26, 2004
    #3
  4. rokia

    grahamo Guest

    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 .
    grahamo, Jul 26, 2004
    #4
  5. "rokia" <> schrieb im Newsbeitrag
    news:ce29mq$1f2m$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
    Gernot Frisch, Jul 26, 2004
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jeremy Lemaire
    Replies:
    3
    Views:
    524
    Ivan Vecerina
    Oct 10, 2003
  2. blugus
    Replies:
    5
    Views:
    898
    blugus
    Dec 23, 2003
  3. viza
    Replies:
    4
    Views:
    300
    Flash Gordon
    Dec 13, 2007
  4. iq
    Replies:
    0
    Views:
    215
  5. Jason
    Replies:
    0
    Views:
    186
    Jason
    Jul 6, 2004
Loading...

Share This Page