# Meta Arrow Fix Memory Leaks

Luis Ibanez
2010-12-23
A review of the MetaArrowConverter code revealed that this class does not use any state information (does not have any member variables) and therefore all of its methods can be declared static. The arguments of many of the methods were also missing to use a 'const' declaration, despite the fact that the execution of the function did not modified the content of the argument.

The main API change here is that now MetaArrowConverter is an ITK object and it has to be constructed with the typical SmartPointer notation of

MetaArrowConverterType::Pointer converter = MetaArrowConverterType::New();

while before it could be constructed as:

MetaArrowConverterType converter;

The default constructor has now been declared 'protected' so the second notation will result in compilation errors.

BUG: MetaArrow memory leaks. MetaArrowConverter is now an ITK Object and uses smart pointers. Several delete were added to places where irresponsible calls to new MetaArrow were done without regards for cleaning up the allocations.

ENH: Fixing const in ArrowSpatialObject::GetLength.

ENH: Making most methods of itkMetaArrowConverter to be static, since this class doesn&apos;t really have a state (no member variables). As pointed out by Brad Lowekamp during Gerrit review.
typedef MetaArrowConverter<Dimension> MetaArrowConverterType; MetaArrowConverterType converter;
typedef MetaArrowConverter<Dimension> MetaArrowConverterType; MetaArrowConverterType::Pointer converter = MetaArrowConverterType::New();

SpatialObjectPointer spatialObject = converter->ReadMeta( inputFilename ); converter->WriterMeta( spatialObject, outputFilename );

MetaArrow * arrow = GetArrowSomeHow(); SpatialObjectPointer arrowObject = converter->MetaArrowToArrowSpatialObject( arrow );

MetaArrow * anotherArrow = converter->ArrowSpatialObjectToMetaArrow( arrowObject );

// // Or with the static notation: // SpatialObjectPointer spatialObject = MetaArrowConverterType::ReadMeta( inputFilename ); MetaArrowConverterType::WriterMeta( spatialObject, outputFilename );

MetaArrow * arrow = GetArrowSomeHow(); SpatialObjectPointer arrowObject = MetaArrowConverterType::MetaArrowToArrowSpatialObject( arrow );

MetaArrow * anotherArrow = MetaArrowConverterType::ArrowSpatialObjectToMetaArrow( arrowObject );
I6c4eafc97cf2c3859d9a624985494ebe680d6044
Code/SpatialObject/itkArrowSpatialObject.h Code/SpatialObject/itkMetaArrowConverter.h Code/SpatialObject/itkMetaArrowConverter.txx Code/SpatialObject/itkMetaSceneConverter.txx Testing/Code/SpatialObject/itkMetaArrowConverterTest.cxx