This site is no longer active and is available for archival purposes only. Registration and login is disabled.

stl::vector leak?


stl::vector leak?

Postby izeman » Mar 29, 2004 @ 10:47am

User avatar
izeman
pm Member
 
Posts: 72
Joined: Aug 10, 2003 @ 1:30pm
Location: cebu, philippines


Postby Kzinti » Mar 29, 2004 @ 11:42pm

Kzinti
pm Member
 
Posts: 3238
Joined: Jan 13, 2002 @ 5:23am


Postby izeman » Mar 30, 2004 @ 2:03pm

User avatar
izeman
pm Member
 
Posts: 72
Joined: Aug 10, 2003 @ 1:30pm
Location: cebu, philippines


Postby angedelamort » Mar 30, 2004 @ 3:19pm

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.
User avatar
angedelamort
pm Member
 
Posts: 304
Joined: Mar 7, 2002 @ 11:16pm
Location: Montreal, Quebec


Postby Pejo Software - Per » Mar 30, 2004 @ 3:30pm

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.
User avatar
Pejo Software - Per
pm Insider
 
Posts: 343
Joined: Apr 25, 2002 @ 1:00pm
Location: Mölndal, Sweden


Postby mlepage » Mar 30, 2004 @ 4:57pm

I believe behaviour is undefined if you use new[] but not delete[].
www.scalenesoftware.com
Great games for your Palm and Pocket PC!
User avatar
mlepage
pm Insider
 
Posts: 1050
Joined: Aug 3, 2003 @ 4:47am
Location: Canada


Postby Kzinti » Mar 30, 2004 @ 5:11pm

Kzinti
pm Member
 
Posts: 3238
Joined: Jan 13, 2002 @ 5:23am


Postby Pejo Software - Per » Mar 30, 2004 @ 9:06pm

User avatar
Pejo Software - Per
pm Insider
 
Posts: 343
Joined: Apr 25, 2002 @ 1:00pm
Location: Mölndal, Sweden


Postby izeman » Mar 31, 2004 @ 12:49am

User avatar
izeman
pm Member
 
Posts: 72
Joined: Aug 10, 2003 @ 1:30pm
Location: cebu, philippines


Postby izeman » Mar 31, 2004 @ 12:56am

User avatar
izeman
pm Member
 
Posts: 72
Joined: Aug 10, 2003 @ 1:30pm
Location: cebu, philippines


Postby izeman » Mar 31, 2004 @ 1:42am

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
User avatar
izeman
pm Member
 
Posts: 72
Joined: Aug 10, 2003 @ 1:30pm
Location: cebu, philippines


Postby Kzinti » Mar 31, 2004 @ 1:55am

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.
Kzinti
pm Member
 
Posts: 3238
Joined: Jan 13, 2002 @ 5:23am


Postby izeman » Mar 31, 2004 @ 2:25am

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
User avatar
izeman
pm Member
 
Posts: 72
Joined: Aug 10, 2003 @ 1:30pm
Location: cebu, philippines


Postby izeman » Mar 31, 2004 @ 2:29am

User avatar
izeman
pm Member
 
Posts: 72
Joined: Aug 10, 2003 @ 1:30pm
Location: cebu, philippines


Postby Kzinti » Mar 31, 2004 @ 3:10am

Kzinti
pm Member
 
Posts: 3238
Joined: Jan 13, 2002 @ 5:23am


Next

Return to Windows Mobile


Sort


Forum Description

A discussion forum for mobile device developers on the Windows Mobile platform. Any platform specific topics are welcome.

Moderators:

Dan East, sponge, Digby, David Horn, Kevin Gelso, RICoder

Forum permissions

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

cron