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.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,758ad7877a64226f X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-05-10 05:41:57 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!c03.atl99!news.webusenet.com!pc01.webusenet.com!fe08.atl2.webusenet.com.POSTED!not-for-mail From: "David C. Hoos" Newsgroups: comp.lang.ada References: <3ebcea42$1_4@news.arrakis.es> Subject: Re: deallocating class wide types MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Newsreader: Microsoft Outlook Express 6.00.2800.1106 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 Message-ID: X-Complaints-To: abuse@usenetserver.com X-Abuse-Info: Please be sure to forward a copy of ALL headers X-Abuse-Info: Otherwise we will be unable to process your complaint properly. NNTP-Posting-Date: Sat, 10 May 2003 08:39:42 EDT Date: Sat, 10 May 2003 07:41:48 -0500 Xref: archiver1.google.com comp.lang.ada:37145 Date: 2003-05-10T07:41:48-05:00 List-Id: "alfonso acosta" wrote in message news:3ebcea42$1_4@news.arrakis.es... > hi: > > I provide a simplified example of my problem: > > package spec: > ---------------------------------------------------------------- > package My_Class is > > type My_Class is abstract tagged null record; > type My_Class_Access is access all My_Class'Class; > procedure Destroy (Object: in out My_Class_Access); > > end My_Class; > ---------------------------------------------------------------- > > first body approach: > ---------------------------------------------------------------- > with Ada.Unchecked_Deallocation; > package body My_Class is > procedure Free is > new Ada.Unchecked_Deallocation(Name => My_Class_Access, > Object => My_Class'Class); > > procedure Destroy (Object: in out My_Class_Access) renames Free; > > end My_Class; > ---------------------------------------------------------------- > > I get: > my_class.adb:7:59: subprogram used in renaming_as_body cannot be intrinsic The error message means exactly what it says -- you cannot rename an intrinsic subprogram. If you wish to directly use an instantiation of Ada.Unchecked_Deallocation, then you must instantiate it in the package specification -- e.g. procedure Destroy is new Ada.Unchecked_Deallocation(Name => My_Class_Access, Object => My_Class'Class); > > second approach: > ---------------------------------------------------------------- > with Ada.Unchecked_Deallocation; > package body My_Class is > procedure Free is > new Ada.Unchecked_Deallocation(Name => My_Class_Access, > Object => My_Class'Class); > > procedure Destroy (Object: in out My_Class_Access) is > begin > Free(My_Class_Access); > end Destroy; > > end My_Class; > ------------------------------------------------------------------ > > I get: > my_class.adb:9:09: Invalid use of subtype mark in expression or call Again, the message means exactly what it says -- you cannot use a type as the argument in a subprogram call. You should have written Free (Object); > > Can someone tell me what Im doing wrong? > And, should Destroy work with any type which extends My_Class? The answer is maybe. If none of the extensions to your class will ever use an access object as one of its components, it will work. But if an extension of your class uses access to a type not derived from Ada.Finalization, then the memory for the object designated by that access component will be "orphaned" -- i.e. you will have a "memory leak." > > Thanks in advance: > > Alfonso Acosta > > _______________________________________________ > comp.lang.ada mailing list > comp.lang.ada@ada.eu.org > http://ada.eu.org/mailman/listinfo/comp.lang.ada > >