Memory leaks reported creating simple array of class

F

Fred

Hi,
I came across code which stores class pointers in an array.

I have simplified it below. When I run the code I get a memory leak reported
in VC6.

Any idea why and is it something to worry about or just an artifact of the
debugger?

class CTest
{
};

void main(void)
{

CTest *TData = new CTest[4];
_CrtDumpMemoryLeaks();

}
 
F

Fred

Fred said:
Hi,
I came across code which stores class pointers in an array.

I have simplified it below. When I run the code I get a memory leak reported
in VC6.

Any idea why and is it something to worry about or just an artifact of the
debugger?

class CTest
{
};

void main(void)
{

CTest *TData = new CTest[4];
_CrtDumpMemoryLeaks();

}

Forget that simplification

CTest *TData = new CTest[4];
delete []TData;
_CrtDumpMemoryLeaks();

gives no memory leak of course.

I'll have a further look at the original sample (it gives the leak even
after the delete).
 
F

Fred

Forget that simplification

CTest *TData = new CTest[4];
delete []TData;
_CrtDumpMemoryLeaks();

gives no memory leak of course.

I'll have a further look at the original sample (it gives the leak even
after the delete).


Whoops silly me. _CrtDumpMemoryLeaks(); was being called before the delete.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top