how to release 'new DcmFileFormat'

All other questions regarding DCMTK

Moderator: Moderator Team

Post Reply
Message
Author
hiterneol
Posts: 1
Joined: Thu, 2006-06-29, 23:24

how to release 'new DcmFileFormat'

#1 Post by hiterneol »

DcmFileFormat *dfile = new DcmFileFormat();
OFCondition cond =dfile->loadFile(dlg.GetFileName(), EXS_Unknown,EGL_withoutGL,DCM_MaxReadLength,(const E_FileReadMode)OFFalse);

But I can't release variable 'dfile' by delete, such as

delete dfile;
dfile = NULL;

if I don't release 'dfile', there will be memory leak, anybody can help me?

Marco Eichelberg
OFFIS DICOM Team
OFFIS DICOM Team
Posts: 1446
Joined: Tue, 2004-11-02, 17:22
Location: Oldenburg, Germany
Contact:

#2 Post by Marco Eichelberg »

But I can't release variable 'dfile' by delete, such as
delete dfile;
Why not?

cmasson
Posts: 2
Joined: Wed, 2006-11-29, 17:28
Location: France

#3 Post by cmasson »

Hi.

I am facing the same kind of problem when trying to build a multiframe dicom file.

1 - A DcmFileFormat object is created.
2 - A DcmPixelSequence object is created (with a DCM_PixelData tag).
3 - For each image, a DcmPixelItem object is created and inserted into the pixel sequence.
3 - A DcmPixeltem object is created to build an offset table ; that pixel item is inserted into the pixel sequence with prepend().
4 - The pixel sequence is inserted into the dataset of the DcmFileFormat object.
5 - The method save() of DcmFileFormat is called to create the file.
6 - "delete" is applied to the DcmFileFormat, the DcmPixelSequence and the set of DcmPixelItem.

Then the process crashes...

Is there anything wrong with that way? Thanks for any clue.

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

#4 Post by Jörg Riesmeier »

After you've inserted the pixel item and pixel sequence, you should not delete these objects manually. So, in step 6 just omit the deletion of the DcmPixelSequence and the DcmPixelItem objects.

cmasson
Posts: 2
Joined: Wed, 2006-11-29, 17:28
Location: France

#5 Post by cmasson »

Hello.

Thanks for your answer. However, even when I delete no other object than the DcmFileFormat object, the process crashes when ~DcmItem() is called.

Marco Eichelberg
OFFIS DICOM Team
OFFIS DICOM Team
Posts: 1446
Joined: Tue, 2004-11-02, 17:22
Location: Oldenburg, Germany
Contact:

#6 Post by Marco Eichelberg »

Sounds like you need to work through your code with a memory debugger tool such as valgrind. There could be various reasons for the problem you describe, one being that an object created on the stack (and not on the heap) is inserted into the DcmFileFormat tree of objects somewhere.

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 1 guest