From: Maciej Sobczak <see.my.homepage@gmail.com>
Subject: Unchecked_Deallocation of class-wide objects
Date: Mon, 28 Sep 2009 01:43:03 -0700 (PDT)
Date: 2009-09-28T01:43:03-07:00 [thread overview]
Message-ID: <9b4410c1-17a9-434c-b0e5-75843364ca36@r31g2000vbi.googlegroups.com> (raw)
Is it legal and safe to deallocate class-wide objects?
The problem is that such an object is allocated with its concrete
type, whereas deallocation is defined for its class-wide type.
Consider:
type Shape is tagged private;
type Shape_Access is access Shape'Class;
procedure Free_Shape is new Ada.Unchecked_Deallocation
(Object => Shape'Class, Name => Shape_Access);
-- ...
type Circle is new Shape with ...
-- ...
C : Shape_Access := new Circle;
-- ...
Free_Shape (C);
Is the Circle object allocated on the Shape-wide storage pool? From
what I understand, this is the condition for the above to work
properly.
What if Circle is allocated for some Circle_Access type which is then
converted to Shape_Access? Can it be safely deallocated?
I believe that the above is a pretty standard use-case, but I would
like to confirm that. Unfortunately, AARM is not very explicit about
this subject.
--
Maciej Sobczak * www.msobczak.com * www.inspirel.com
Database Access Library for Ada: www.inspirel.com/soci-ada
next reply other threads:[~2009-09-28 8:43 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-09-28 8:43 Maciej Sobczak [this message]
2009-09-28 9:12 ` Unchecked_Deallocation of class-wide objects Dmitry A. Kazakov
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox