comp.lang.ada
 help / color / mirror / Atom feed
From: Peter Chapin <PChapin@vtc.vsc.edu>
Subject: Re: Deallocating an object twice
Date: Sun, 27 Jul 2014 08:47:15 -0400
Date: 2014-07-27T08:47:15-04:00	[thread overview]
Message-ID: <WvGdnQWki_tJaUnORVn_vwA@giganews.com> (raw)
In-Reply-To: <lr2nse$ahi$1@speranza.aioe.org>

On 2014-07-27 07:30, anon@att.net wrote:

> 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.

C's free() marks the memory as unused in the sense that a future call to
malloc() might use memory that was previously freed. If that were not
the case it wouldn't be possible, even in principle, to write a C
program that didn't leak memory.

What you're talking about is happening at a lower level. It may be the
case that once a block of memory is requested from the OS, the C library
never releases it. As you say, the OS reclaims the memory when the
process terminates. However, the C library will still distinguish
between used and unused memory within the allocation it has.

A program that loops forever repeatedly allocating and freeing memory
for a single integer, say, could run infinitely without ever exhausting
storage or requesting additional memory from the OS. It will simply
reuse the space it already has.

Peter


  reply	other threads:[~2014-07-27 12:47 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
2014-07-27 12:47   ` Peter Chapin [this message]
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