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,56131a5c3acc678e X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-12-03 01:29:23 PST Path: archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.fjserv.net!newsfeed.freenet.de!fr.ip.ndsoftware.net!teaser.fr!wanadoo.fr!not-for-mail From: Pascal Obry Newsgroups: comp.lang.ada Subject: Re: Question about OO programming in Ada Date: 03 Dec 2003 10:29:17 +0100 Organization: Home - http://perso.wanadoo.fr/pascal.obry Message-ID: References: <8urxb.19482$sb4.18182@newsread2.news.pas.earthlink.net> <1792884.HtYz4Yv8lY@linux1.krischik.com> NNTP-Posting-Host: avelizy-103-1-5-2.w80-13.abo.wanadoo.fr Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: news-reader4.wanadoo.fr 1070443762 503 80.13.115.2 (3 Dec 2003 09:29:22 GMT) X-Complaints-To: abuse@wanadoo.fr NNTP-Posting-Date: 3 Dec 2003 09:29:22 GMT User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2.95 Xref: archiver1.google.com comp.lang.ada:3090 Date: 2003-12-03T09:29:22+00:00 List-Id: Dmitry A. Kazakov writes: > Easily if the target is controlled. Consider this: > > with Ada.Finalization; > package A is > type Misty is > new Ada.Finalization.Limited_Controlled with null record; > procedure Finalize (X : in out Misty); > end A; > > with Text_IO; use Text_IO; > package body A is > procedure Finalize (X : in out Misty) is > begin > Put_Line ("finalized!"); > end Finalize; > end A; > > with A; use A; > with Text_IO; use Text_IO; > procedure Test is > begin > Put_Line ("Begin of a scope"); > declare > type Pointer is access all Misty; > X : Pointer; > begin > X := new Misty; -- This is not dangled! Of course it is. > end; > Put_Line ("End of the scope"); > end Test; > > This program should print; > > Begin of a scope > finalized! > End of the scope And it has a nice memory leak. > All controlled objects allocated by the allocator new, being not > explicity destroyed using Unchecked_Deallocation, will be destroyed > upon finalization of the access type. There is no magic done by Finalize here ! Finalize gives a chance to the component implementer to do the memory deallocation for the end user. That's all. Pascal. -- --|------------------------------------------------------ --| Pascal Obry Team-Ada Member --| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE --|------------------------------------------------------ --| http://perso.wanadoo.fr/pascal.obry --| "The best way to travel is by means of imagination" --| --| gpg --keyserver wwwkeys.pgp.net --recv-key C1082595