1

I'm using BoundsChecker9.1 with visual c++. I have a class

class Sample{
public:
vector<AnotherClass> x;
};

When I run my program the BoundsChecker tool reports all push_back() calls such as S.x.push_back(AnotherClass()) as memory leak.. Wouldn't all the elements in vector x will always be deallocated when the Sample class goes out of scope? If so, any idea about why BoundsChecker is showing them as memory leak? And I verified that "AnotherClass" doesnt have any memory leak either!!

Georg Fritzsche
  • 97,545
  • 26
  • 194
  • 236
Prabhu
  • 3,434
  • 8
  • 40
  • 48

1 Answers1

4

If the constructor of AnotherClass allocates memory which isn't deallocated in ~AnotherClass you will have a memory leak.

Andreas Brinck
  • 51,293
  • 14
  • 84
  • 114