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=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,2e589dbfe40b0d25 X-Google-Attributes: gid103376,public From: Laurent Guerby Subject: Re: Deallocating an object referenced via a classwide access type. Date: 2000/01/11 Message-ID: <86k8lgmmig.fsf@ppp-112-82.villette.club-internet.fr>#1/1 X-Deja-AN: 571303647 References: X-Trace: front3.grolier.fr 947618924 2744 194.158.112.82 (11 Jan 2000 19:28:44 GMT) Organization: Club-Internet (France) NNTP-Posting-Date: 11 Jan 2000 19:28:44 GMT Newsgroups: comp.lang.ada Date: 2000-01-11T19:28:44+00:00 List-Id: Aidan wrote: > I can't use Ada.Unchecked_Deallocation, since My_Thing might be a Foo > or it might be a New_Foo. May be I'm missing something obvious about your question and/or the Ada RM but the code attached at the end of this message works for AFAIK (I edited your spec so that it compiles ;-). The only thing special (due to the class wide nature of the Object formal) is that the Finalize call made as part of the Free call before returning the memory to the system will be dispatching (you didn't provide Finalize on Foo but I guess you have one ;-). --LG with Ada.Unchecked_Deallocation; package body Foo_Package is procedure Deallocate (Object : in out Foo) is procedure Free is new Ada.Unchecked_Deallocation (Foo'Class, Foo_Access); begin Free (Object.My_Thing); end Deallocate; end Foo_Package; with Ada.Finalization; package Foo_Package is type Foo is new Ada.Finalization.Controlled with private; type Foo_Access is access all Foo'Class; type New_Foo is new Foo with private; private type Foo is new Ada.Finalization.Controlled with record My_Thing : Foo_Access := null; end record; procedure Deallocate (Object : in out Foo); type New_Foo is new Foo with null record; end Foo_Package;