From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,c748ccb05f2e3925,start X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!postnews.google.com!r31g2000vbi.googlegroups.com!not-for-mail From: Maciej Sobczak Newsgroups: comp.lang.ada Subject: Unchecked_Deallocation of class-wide objects Date: Mon, 28 Sep 2009 01:43:03 -0700 (PDT) Organization: http://groups.google.com Message-ID: <9b4410c1-17a9-434c-b0e5-75843364ca36@r31g2000vbi.googlegroups.com> NNTP-Posting-Host: 137.138.182.236 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 X-Trace: posting.google.com 1254127383 15122 127.0.0.1 (28 Sep 2009 08:43:03 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Mon, 28 Sep 2009 08:43:03 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: r31g2000vbi.googlegroups.com; posting-host=137.138.182.236; posting-account=bMuEOQoAAACUUr_ghL3RBIi5neBZ5w_S User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3,gzip(gfe),gzip(gfe) Xref: g2news2.google.com comp.lang.ada:8506 Date: 2009-09-28T01:43:03-07:00 List-Id: 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