[Insight-developers] DataObject:Initialize
Miller, James V (Research)
millerjv at crd . ge . com
Fri, 27 Jun 2003 08:44:28 -0400
John,
The purpose of Initialize() is to return the data object
to a state that is consistent with how a newly constructed
object appear. This translates to the "bulk" data being
released.
Let's assume for the moment that your ChainCodePath object
stores the chain code in an std::vector. Then the Initialize()
routine can keep the same std::vector object around but should
force the std::vector to release its memory. This sounds simply
enough but it is very hard to get STL to actually free up memory.
For instance, if you call std::vector.resize(0), the memory of
for your vector can still be associated with your object just incase
that particular std::vector needs it again. The situation is even
worse for std::list because STL keeps the memory for nodes you
delete just in case ANY std::list with the same size node may
need memory.
The former situation can be handled by keeping a pointer to an
std::vector and deleting/reallocating the std::vector in the
Initialize() routine. For the latter case, the best you can
do is just delete the nodes in the list. If both cases, however,
the memory is returned to some sort of "free pool" so that your
application can reclaim it for other objects.
If you follow the implementations of Initialize() of the Image classes,
you will see the situation there is a little more complicated than the
above because multiple image objects could "share" the same data
container. In these instances, the other consumers of the data
container are holding smart pointers to the data container, so the
Image being Initialize()'d just creates itself a new data container.
The other consumers of the data container will still reference
the old (and still valid) data container. This is the safest thing
to do in this particular instance. However, I don't imagine that
this situation is analogous to how paths are passed around. I just
wanted to point it out so that you are aware that the code in Image
is more conservative that one usually needs to be in Initialize().
> -----Original Message-----
> From: John M. Galeotti [mailto:jgaleotti at cmu . edu]
> Sent: Thursday, June 26, 2003 3:55 PM
> To: insight-developers at itk . org
> Subject: [Insight-developers] DataObject:Initialize
>
>
> Hello, I am making Path descend from DataObject, and I have a
> question
> about the Initialize() function, which is incidentally called by
> ReleaseData(). My question is whether or not I should
> de-allocate all
> the memory used to store a path in the Initialize function. Is the
> following acceptable behavior?
>
> ChainCodePath::Initialize
> Set start index to origin
> Clear (and possibly deallocate) all steps in the chain
> code (make it 0
> length)
> Do NOT deallocate the chain code object itself
>
> ParametricPath::Initialize
> Set to default, unassigned state, which may be undefined
> Do NOT deallocate the parametric path object itself
>
>
> The above behavior seems to allow correct behavior when
> ShouldReleaseData is turned on, but I'm not sure. Could
> someone please
> help clarify.
>
> Thank you,
> John Galeotti
> jgaleotti at cmu . edu
>
> _______________________________________________
> Insight-developers mailing list
> Insight-developers at itk . org
> http://www . itk . org/mailman/listinfo/insight-developers
>