In the code that follows I am trying to load a series of dicom images from
a directory and store them in a single 3d array...
Code: Select all
/********************/
Here is var declaration:
DicomImage *di;
DcmFileFormat dfile;
DcmDataset *dataset;
/******************/
Here is pseudo code
for number of images in directory
{
dfile.loadFile (file_name);
dataset = dfile.getDataset ();
xfer = dataset->getOriginalXfer ();
mode = CIF_MayDetachPixelData | CIF_TakeOverExternalDataset;
di = new DicomImage (&dfile, xfer, mode);
di->getOutputData (....);
di->deleteOutputData ();
delete di ; <---------!!!!!!!!!!!!!!!!!!-------------- segmentation fault.
}
So my question is how to free DcmDataset and DicomImage pointers,
which should be freed first, which is dependent on which?
I have profiled this piece of code ( without deleting di ) using rational
purify and I get memory leaks if i do not use delete di. If I use "delete di" I get
segmentation faults.
Unfortunately DCMTK example code shows only how to do memory allocation in a stand alone program in which all memory is freed and returned to OS after program exit... What about library wrap code using DCMTK?!
Thanks a lot,
Todor