Page 1 of 2
stl::vector leak?

Posted:
Mar 29, 2004 @ 10:47am
by izeman

Posted:
Mar 29, 2004 @ 11:42pm
by Kzinti

Posted:
Mar 30, 2004 @ 2:03pm
by izeman

Posted:
Mar 30, 2004 @ 3:19pm
by angedelamort
TCHAR *x=new TCHAR[123];
delete x;
In my memory, when I'm using the new [] operator, I think we are supposed to use delete [] operator. So I suspect that there is a leak in that.
For the rest, everything looks fine.

Posted:
Mar 30, 2004 @ 3:30pm
by Pejo Software - Per
Yes you shall use the delete[] but I don't think that this will result in a leak. It just means that destructors won't be called but since TCHAR don't have a destructor...
I also had a quick look at the code and could not find anything that would result in a leak.
You could test to see if there is any difference if you use STLPort instead.

Posted:
Mar 30, 2004 @ 4:57pm
by mlepage
I believe behaviour is undefined if you use new[] but not delete[].

Posted:
Mar 30, 2004 @ 5:11pm
by Kzinti

Posted:
Mar 30, 2004 @ 9:06pm
by Pejo Software - Per

Posted:
Mar 31, 2004 @ 12:49am
by izeman

Posted:
Mar 31, 2004 @ 12:56am
by izeman

Posted:
Mar 31, 2004 @ 1:42am
by izeman
STLPort 4.5.3
also leaked...
even with Pejo's ... virtual ~IObject() {};
is there a method other than clear() that frees up everything vector allocates?
or guess i'll move on and use a primitive linked list
i'll probably save a few kbs from not creating many vector templates

Posted:
Mar 31, 2004 @ 1:55am
by Kzinti
How about you fix the reinterpret_cast<> and the delete [] problems before blaming STLport? Or did you fix them?
You don't have anything to do to clear a vector, it will take care of itself.

Posted:
Mar 31, 2004 @ 2:25am
by izeman
yes, i removed the tchar[] delete.. and used static_cast as you suggested.
it resulted in two leaks
1304 bytes long and 320 bytes long,
i had a _CrtSetBreakAlloc(45) ... this one is inside the push_back method
note:
vc++ only produced one leak 64 bytes long...
i used a simple array instead of vector, no leak is produced...
i'll check other ways to reproduce the leak without reinterpret_cast or static_cast

Posted:
Mar 31, 2004 @ 2:29am
by izeman

Posted:
Mar 31, 2004 @ 3:10am
by Kzinti