comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: Allocators and exceptions
Date: Mon, 10 Sep 2007 21:36:56 -0500
Date: 2007-09-10T21:36:56-05:00	[thread overview]
Message-ID: <fc4uqq$ij6$1@jacob-sparre.dk> (raw)
In-Reply-To: 1189323618.588340.87180@o80g2000hse.googlegroups.com

"Maciej Sobczak" <see.my.homepage@gmail.com> wrote in message
news:1189323618.588340.87180@o80g2000hse.googlegroups.com...
> What happens when during the initialization of the newly allocated
> object an exception is raised?
>
> I cannot find anything in the AARM that covers this case. What I want
> to find exactly is the *guarantee* that the allocated memory is
> automatically reclaimed.
> Any relevant paragraph numbers are highly welcome.

Amplifying Adam's response:

(1) Nothing in the Ada standard is about "goodness". In particular, there is
nothing anywhere in the standard that resources like memory ever get
reclaimed. I suspect most implementers will in fact do reclamation (and
avoid leaks), but it is not part of the Ada language as described by the
standard.

(2) I believe that the current wording of the standard *requires* that
reclamation *not* be performed in examples like this, at least if there are
any controlled components in the type. That's because there is no permission
in Ada to do finalization early - it has to be done only if the object is
explicitly destroyed or when the master goes out of scope -- which for an
allocated object is when the *type* goes out of scope.

(Not everyone agrees with the above opinion, but everyone does agree that it
is an issue in some cases. But there is nothing close to an agreement on how
to fix the standard, so don't hold your breath waiting for a fix...)

Yes, this also means that an Ada compiler implementing garbage collection is
mostly likely incorrect. It's highly unlikely, however, that anyone will be
testing for such "errors" formally. I did write an ACATS-style test for a
case like this and determined that most compilers do in fact finalization
the object at the appropriate time: which suggests that they leak memory in
this case.

Moral: Never, ever, write code that intentionally raises an exception during
an allocator. (Unintentional exceptions are just plain bugs and ought to get
fixed in testing.)  Better still, don't use any allocators at all (use the
predefined containers if you need dynamic memory management).

                                   Randy.


For what





  parent reply	other threads:[~2007-09-11  2:36 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-09-09  7:40 Allocators and exceptions Maciej Sobczak
2007-09-09 12:17 ` anon
2007-09-09 20:31   ` Maciej Sobczak
2007-09-09 22:43     ` Simon Wright
2007-09-10 12:10       ` Maciej Sobczak
2007-09-10 19:08         ` Simon Wright
2007-09-10  2:56     ` anon
2007-09-10 12:42     ` Dmitry A. Kazakov
2007-09-10 21:48       ` Maciej Sobczak
2007-09-11  9:16         ` Dmitry A. Kazakov
2007-09-11  9:19           ` Maciej Sobczak
2007-09-11 12:27             ` Dmitry A. Kazakov
2007-09-11 19:07               ` Maciej Sobczak
2007-09-11 22:56                 ` Georg Bauhaus
2007-09-12 12:36                   ` Maciej Sobczak
2007-09-12 22:19                     ` Randy Brukardt
2007-09-12  9:32                 ` Dmitry A. Kazakov
2007-09-12 12:42                   ` Maciej Sobczak
2007-09-12 15:25                     ` Dmitry A. Kazakov
2007-09-12 12:29             ` Stephen Leake
2007-09-12 12:46               ` Maciej Sobczak
2007-09-12 20:53                 ` Simon Wright
2007-09-12 22:32                   ` Randy Brukardt
2007-09-12 23:43                     ` Simon Wright
2007-09-13  3:42                       ` Randy Brukardt
2007-09-13  3:36                     ` Randy Brukardt
2007-09-13  9:43                     ` Maciej Sobczak
2007-09-12 22:25                 ` Randy Brukardt
2007-09-13 11:51                 ` Stephen Leake
2007-09-12 14:14               ` Markus E L
2007-09-10 10:37 ` Allocators and exceptions => Read Me First anon
2007-09-10 12:16   ` Maciej Sobczak
2007-09-10 22:10     ` Allocators and exceptions => Trying Again anon
2007-09-10 23:15       ` Markus E L
2007-09-10 15:44 ` Allocators and exceptions Adam Beneschan
2007-09-10 21:58   ` Maciej Sobczak
2007-09-10 22:07   ` Jeffrey R. Carter
2007-09-11  9:14   ` Dmitry A. Kazakov
2007-09-11  9:23     ` Maciej Sobczak
2007-09-11  2:36 ` Randy Brukardt [this message]
2007-09-11 15:33   ` Adam Beneschan
2007-09-11 19:21     ` Maciej Sobczak
2007-09-11 21:56     ` Adam Beneschan
2007-09-12  0:34       ` Jeffrey R. Carter
2007-09-12 12:13         ` Maciej Sobczak
2007-09-12 16:34           ` Jeffrey R. Carter
2007-09-12 23:50             ` Jeffrey R. Carter
2007-09-12 12:22       ` Maciej Sobczak
2007-09-12 14:11         ` Markus E L
2007-09-12 16:08         ` Adam Beneschan
2007-09-12 20:35           ` Dmitry A. Kazakov
2007-09-12 21:01             ` Adam Beneschan
2007-09-12 22:45             ` Randy Brukardt
2007-09-13  7:48               ` Dmitry A. Kazakov
2007-09-12  3:08 ` Allocators and exceptions -- Debugging says memory leak! anon
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox