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.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,6b1a1ed8b075945 X-Google-Attributes: gid103376,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news4.google.com!feeder1-2.proxad.net!proxad.net!feeder2-2.proxad.net!newsfeed.arcor.de!newsspool2.arcor-online.net!news.arcor.de.POSTED!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Allocators and exceptions Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.15.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: <1189323618.588340.87180@o80g2000hse.googlegroups.com> <1189369871.672082.162750@50g2000hsm.googlegroups.com> Date: Mon, 10 Sep 2007 14:42:42 +0200 Message-ID: NNTP-Posting-Date: 10 Sep 2007 14:37:32 CEST NNTP-Posting-Host: 009dbd93.newsspool2.arcor-online.net X-Trace: DXC=S>WcEg98hI=RadXUBHgFh3A9EHlD;3Yc24Fo<]lROoR1<`=YMgDjhg2Gl0dm7enW;^6ZC`4IXm65S@:3>?T=CP=EQ4TG3 X-Complaints-To: usenet-abuse@arcor.de Xref: g2news2.google.com comp.lang.ada:1859 Date: 2007-09-10T14:37:32+02:00 List-Id: On Sun, 09 Sep 2007 13:31:11 -0700, Maciej Sobczak wrote: > Consider: > > procedure P is > > type T (Init : Integer) is record > C : Positive := Positive (Init); > end record; > > type T_Access is access T; > > Ptr : T_Access; > > begin > Ptr := new T (-5); > exception > when Constraint_Error => > -- is memory leaked or deallocated? > null; > end; > > I want to know whether the memory that was allocated for the new > object was immediately deallocated due to the exception. > By "immediately" I mean before the control even goes to the exception > part. > > I don't find this guarantee anywhere in the AARM and it scares me. The question is not only about deallocation, it is also about finalization of the components initialized before the initialization raised an exception. Components are initialized in an arbitrary order. I cannot tell for sure, but I guess that your example is a bounded error. Depending on the compiler the effect should be either Constraint_Error and everything rolled back including memory allocation, or else it is Program_Error + some mess. But you should really ask a language lawyer. P.S. Exceptions in constructors is a bad idea. Consider this: type T (Init : Integer) is record B : access Positive := new Positive; C : Positive := Positive (Init); end record; Ptr := new T (-5); Now you might really want the compiler not to deallocate Ptr, so that you were able to free Ptr.B before. But where do you know that B was initialized? -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de