c++ - why vector pointer's memory automatically cleared -


bs: i've tested, question below vs2010 specific, in test on mingw, vector memory leak, printf("%d\n", testv->size()); gives me '10', shows it's leak.

in codes below:

class test{ public:     std::vector<int> *num;     int *n; };  test *t = new test(); t->num = new std::vector<int>; t->num->assign(10,10); t->n = new int[20]; t->n[0] = 12345; int *testn = t->n; std::vector<int> *testv;  testv = t->num; delete t;  //i can print n's memory printf("%d\n", testn[0]);  //get 12345, memory leaked here.  //i can't print num's memory; size 0. in release version, it's negative number. printf("%d\n", testv->size()); 

after deleting t, see memory num points cleared, in vs10 environment, see memory cleaned 'ee fe ee fe....'. memory of n stays same.

in opinion, memory comes keyword new, should freed delete, well, here num (vector) not 'delete'd, rather cleared automatically.

i want know how vector pointer different other ones?

the debug runtime overwrite memory deletes marker eefe detect bugs use-after-free. release build not this.

you misreading debug output. both vector* , int* memory still around. debugger trying smarter vectors.


Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -