William McCarty
William McCarty

Reputation: 839

memory leak from vector

I'm seeing I'm getting a memory leak from my vector I have, I've tried deleting the contents then clearing the vector, erasing the vector as well. My Crtdb is still informing me of memory leaks, I know it involves the vector because when i comment all vector related things i get no leaks. Here is all my code is doing.

#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
#include <vector>
#include "MyClass.h"

int main(void){
    Obj *a = new Obj();
    std::vector<Obj> vec;
    vec.push_back(*a);

    Obj b = vec[0];

    vec.erase(vec.begin(),vec.end());
    delete a;
    _CrtDumpMemoryLeaks();
    return 0;
}

Upvotes: 3

Views: 227

Answers (1)

Carl Norum
Carl Norum

Reputation: 225202

Your vector hasn't gone out of scope yet when you call the leak checker.

Upvotes: 6

Related Questions