Will I have memory leak problem?

All other questions regarding DCMTK

Moderator: Moderator Team

Post Reply
Message
Author
snie
Posts: 11
Joined: Tue, 2007-01-30, 20:50

Will I have memory leak problem?

#1 Post by snie »

I define a class CTest

class CTest
{
public:
DcmDataset *dataset;
DcmFileFormat fileformat;

CTest()
{
dataset = fileformat.getDataset();
}

~CTest()
{
delete dataset; //free memory at heap associated to this pointer
}
};


and in main function, I delare

main()
{
CTest *test = new CTest;
//adding other lines if needed
delete test; //free memory at heap assocaited to this pointer
}

Problem:
It is encountered the problem of "Unhandled exception at 0x0050d297 in testfolder2.exe: 0xC0000005: Access violation reading location 0xfeeefeee."

Question:
1) If I only remove the "delete dataset" line in the deconstuctor, or if I only remove "delete test" line in main function, there is no error in run-time, but I wonder if there is memory leak assocaited with it.

2) If I replace "delete dataset" by "delete fileformat.getAndRemoveDataset()", no error in run-time, does getAndRemoveDataset free mmeory?

Thanks,

snie
________
Ios games
________
Rhode island medical marijuana
Last edited by snie on Thu, 2011-02-17, 21:49, edited 2 times in total.

Jörg Riesmeier
ICSMED DICOM Services
ICSMED DICOM Services
Posts: 2217
Joined: Fri, 2004-10-29, 21:38
Location: Oldenburg, Germany

#2 Post by Jörg Riesmeier »

Since you did not create the DcmDataset with new() you should not delete it anyway. This is done automatically by the destructor of DcmFileFormat.

Post Reply

Who is online

Users browsing this forum: Baidu [Spider], Bing [Bot], Google [Bot] and 0 guests