Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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;
}
like image 348
William McCarty Avatar asked Apr 12 '26 23:04

William McCarty


1 Answers

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

like image 159
Carl Norum Avatar answered Apr 15 '26 13:04

Carl Norum



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!