comp.lang.ada
 help / color / mirror / Atom feed
From: anon@att.net
Subject: Re: Deallocating an object twice
Date: Sun, 27 Jul 2014 11:30:23 +0000 (UTC)
Date: 2014-07-27T11:30:23+00:00	[thread overview]
Message-ID: <lr2nse$ahi$1@speranza.aioe.org> (raw)
In-Reply-To: lr1142$log$1@speranza.aioe.org


For most OS, deallocation of memory happens only if the program 
exits and returns it's allocated resources back to the OS. And 
for speed the underlying C library routine "free" does not truly
deallocate or mark the memory as unused. Which means passing a 
null pointer to the underlying C library function "free" will not 
generate an error, so neither does Ada.  This is apart of a bigger 
topic call "Garbage Collection".

Note: In the GNAT design if a storage pool is not present, the 
memory access is done by calling "System.Memory.Free" routine 
which only calls the underlying C library. So, no exception 
will be generated.

To correct this and limit the number of memory leaks, a program 
may employ a storage pool ( like the generic abstract package 
System.Storage_Pool ), and add the exception in the deallocation 
routine. But this feature does have this down sides, like slower 
speed and larger footprint for maintaining a allocation tables.

Note: GNAT does have a number of storage pools designs.

As for the exception it would fall under the Storage_Error scope.
The "Program_Error" exception are for special cases. 


In <lr1142$log$1@speranza.aioe.org>, Victor Porton <porton@narod.ru> writes:
>If I understand correctly, it is an undefined behavior (or is it called 
>unbounded error?) if a pool access is deallocated twice with 
>Unchecked_Deallocation.
>
>I think it should be a Program_Error (if checks are on).
>
>Why was not this done even in Ada2012 (not speaking about older Ada)?
>
>It's bad.
>
>Or is it done and I just miss it?
>
>-- 
>Victor Porton - http://portonvictor.org

  parent reply	other threads:[~2014-07-27 11:30 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-26 19:55 Deallocating an object twice Victor Porton
2014-07-26 20:02 ` Victor Porton
2014-07-27  2:39   ` Randy Brukardt
2014-07-27  2:42   ` Randy Brukardt
2014-07-27  8:31 ` Simon Wright
2014-07-27 11:30 ` anon [this message]
2014-07-27 12:47   ` Peter Chapin
2014-07-27 15:29 ` Stephen Leake
2014-07-27 15:34   ` Victor Porton
2014-07-28 15:15     ` Stephen Leake
2014-07-28 16:15       ` Simon Wright
replies disabled

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