comp.lang.ada
 help / color / mirror / Atom feed
From: Alan Jump <alan.jump@gmail.com>
Subject: Re: 4 beginner's questions on the PL Ada
Date: Fri, 9 Aug 2013 16:43:55 -0700 (PDT)
Date: 2013-08-09T16:43:55-07:00	[thread overview]
Message-ID: <ce6f3a55-f168-4d6a-8e5b-0b1cebae5b7d@googlegroups.com> (raw)
In-Reply-To: <92c32083-74f2-4aaa-94cc-9c9e882bfdf4@googlegroups.com>

On Friday, August 9, 2013 4:33:51 PM UTC-7, Adam Beneschan wrote:

> No.  First of all, if you do this on other record types:
> 
> 
>    X := new Record1;
>    X := new Record1;
>    X := new Record1;
> 
> the memory allocated for the first Record1 doesn't get released when the second X is allocated, and so on.  The data is still there in memory.  And it needs to be, in case there was some code in between those allocations that caused something else to point to the record (or to one of its components) in between.  You can't automatically destroy the record objects if something else might be pointing to them.
> 
> But even if nothing else was pointing to them (as in the above example), Ada still doesn't mandate garbage collection--i.e. reclaiming storage that nothing points to.  A compiler *could* generate code to do this automatically, but I don't know of any that do.  Generally, you have to do your own memory management (using Unchecked_Deallocation).  So if you can see that in the above example, memory storage won't automatically be reclaimed, you can see by analogy that tasks won't automatically be terminated either.  
> 
> But there's another factor: if you allocate a task (or a record containing a task), using Unchecked_Deallocation (or automatic memory reclamation) won't terminate the task.  That's just the way the language authors decided.  This discussion has come up before, and it's surprised other people that a task will still run after Unchecked_Deallocation has been used on it, but there were reasons why things are the way they are.  I don't remember the reasons, though. 
> 
>                              -- Adam

So what you have shown here is a classic recipe for a memory leak. That strikes me as poor code design in any language. I was given Java as a first OO language, so maybe that's what spoiled me on memory reclamation, but I still tried to avoid reusing variables unless I was absolutely certain that what I was writing was going to remain in a limited scope.

Turning back to the point at hand, it seems to me that a better example would have been to allocate an array of task types, then examine the 'Image(Current_Task). But then, if one did produce the array of task types, one would then use the array index as the unique task name, yes?

Pardon me whilst I wander off to find more coffee. Something tells me I'm going to need it.

 - -
73 de N5ILN
Alan

  reply	other threads:[~2013-08-09 23:43 UTC|newest]

Thread overview: 70+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-08-09 16:50 4 beginner's questions on the PL Ada Emanuel Berg
2013-08-09 17:09 ` Adam Beneschan
2013-08-09 17:16   ` Emanuel Berg
2013-08-09 17:46     ` Alan Jump
2013-08-09 18:10       ` Emanuel Berg
2013-08-09 19:01   ` Randy Brukardt
2013-08-09 21:38     ` Emanuel Berg
2013-08-09 22:00       ` Jeffrey Carter
2013-08-09 22:16         ` Emanuel Berg
2013-08-10  0:39           ` Anh Vo
2013-08-10  1:24             ` Emanuel Berg
2013-08-10  6:16               ` Simon Wright
2013-08-10 12:13                 ` Emanuel Berg
2013-08-10 17:12               ` Mike H
2013-08-10 17:53                 ` Emanuel Berg
2013-08-10 19:50                   ` Dennis Lee Bieber
2013-08-10 22:23                     ` Emanuel Berg
2013-08-11  7:12                       ` Georg Bauhaus
2013-08-11 12:44                         ` Emanuel Berg
2013-08-11 21:12                           ` Bill Findlay
2013-08-11 21:22                             ` Emanuel Berg
2013-08-12 17:39               ` Anh Vo
2013-08-12 18:15                 ` Anh Vo
2013-08-12 19:57                 ` Simon Wright
2013-08-12 20:13                   ` Anh Vo
2013-08-10  0:52           ` Jeffrey Carter
2013-08-12 19:47         ` Randy Brukardt
2013-08-09 22:08       ` Robert A Duff
2013-08-09 22:23         ` Emanuel Berg
2013-08-09 22:36           ` Robert A Duff
2013-08-09 22:42             ` Emanuel Berg
2013-08-09 23:48               ` Robert A Duff
2013-08-09 23:50                 ` Emanuel Berg
2013-08-09 23:56                 ` Emanuel Berg
2013-08-10  0:44                 ` Jeffrey Carter
2013-08-10  0:51                   ` Robert A Duff
2013-08-09 22:47             ` Alan Jump
2013-08-09 23:33               ` Adam Beneschan
2013-08-09 23:43                 ` Alan Jump [this message]
2013-08-10  0:19                   ` Robert A Duff
2013-08-10  0:52                   ` Jeffrey Carter
2013-08-10  0:48                 ` Robert A Duff
2013-08-09 23:40               ` Robert A Duff
2013-08-09 23:25       ` Dennis Lee Bieber
2013-08-09 18:29 ` Jeffrey Carter
2013-08-09 18:51   ` Adam Beneschan
2013-08-09 19:05     ` Jeffrey Carter
2013-08-09 18:35 ` Simon Wright
2013-08-09 23:21 ` Dennis Lee Bieber
2013-08-09 23:48   ` Emanuel Berg
2013-08-10  2:45     ` Dennis Lee Bieber
2013-08-10  3:33       ` Emanuel Berg
2013-08-10 14:57         ` Shark8
2013-08-10 17:43           ` Emanuel Berg
2013-08-10 17:55             ` Emanuel Berg
2013-08-10 23:15             ` Simon Clubley
2013-08-11 12:16               ` Emanuel Berg
2013-08-12 18:07               ` Adam Beneschan
2013-08-11  0:34             ` Shark8
2013-08-11 12:42               ` Emanuel Berg
2013-08-11 13:24                 ` Peter C. Chapin
2013-08-11 13:37                   ` Emanuel Berg
2013-08-11 15:15                   ` Mike H
2013-08-12 17:56           ` Adam Beneschan
2013-08-10  6:03       ` Jeffrey Carter
2013-08-12 17:17         ` Eryndlia Mavourneen
2013-08-12 17:27           ` Jeffrey Carter
2013-08-10 12:31 ` Emanuel Berg
2013-08-10 12:37   ` Emanuel Berg
2013-08-10 12:52     ` Emanuel Berg
replies disabled

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