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-Thread: 103376,5799fe4f91b50de,start X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!news.glorb.com!newsgate.cistron.nl!newsfeed.stueberl.de!newsfeed.freenet.de!nntp-peering.plus.net!ptn-nntp-feeder02.plus.net!ptn-nntp-spool01.plus.net!ptn-nntp-reader02.plus.net!not-for-mail From: R A Matthews Subject: Possible Memory Leak Date: Fri, 19 Nov 2004 17:27:42 +0000 Newsgroups: comp.lang.ada User-Agent: Pan/0.11.2 (Unix) Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Comment-To: ALL Message-ID: Organization: Customer of PlusNet plc (http://www.plus.net) NNTP-Posting-Host: b05c45d8.ptn-nntp-reader02.plus.net X-Trace: DXC=bMgU=h1L?;?]m?m:Y7QIA:igd3Y`7Rb;>37XnI;[OUC4?of3cO3i:D;N<\Y;H1kXM8Me?nf_Q`BE;Vh;_71W1;A3 X-Complaints-To: abuse@plus.net Xref: g2news1.google.com comp.lang.ada:6292 Date: 2004-11-19T17:27:42+00:00 List-Id: This is probably one for the language lawyers... Consider a type having a pointer to itelf - that is each variable of this type contains its own address; it's not limited so it needs to be controlled - as exemplified by: type My_Type; type Access_My_Type is access all My_Type; type My_Type is new Ada.Finalization.Controlled with record Self : Access_My_Type; end record; Initialize will set Self, and Adjust will maintain it. In addition, the type can point to some data: type My_Type is new Ada.Finalization.Controlled with record Self : Access_My_Type; Data : Access_Some_Data_Type; end record; Each variable of My_Type points to its own set of data so Adjust must copy that data and Finalize must deallocate it. Now the Annotated Reference Manual at 7.6(21 and 21.b) allows a compiler to perform assignment on such a data type via an intermediate temporary variable: The temporary is overwritten from the source variable, then Adjust called for the temporary. The temporary is copied to the target variable then Adjust is called for the target - but only if the data type has an aliased component, so we need to have our data type redeclared as: type Inner_Type is record Self : Access_My_Type; Data : Access_Some_Data_Type; end record; type My_Type is new Ada.Finalization.Controlled with record Inner : aliased Inner_Type; end record; This ensures that the target of the assignment is adjusted, so Self is set correctly and gives the target its own copy of the referenced data. BUT the Standard says that the temporary variable need not be finalized, in which case the temporary's data is not deallocated and so we have a memory leak. It seems that the Standard is OK when we have 1) Just the Self component, or 2) Just the Data component, though without the use of "aliased". However the Standard is not OK when we have: 3) Both Self and Data (whether or not we have used "aliased"). 4) Just the Data component and also have an aliased component. Is the Standard wrong? Enlightenment please! Robert A. Matthews ada at ramatthews dot free-online dot co dot uk