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=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.224.69.6 with SMTP id x6mr14487088qai.0.1376091835836; Fri, 09 Aug 2013 16:43:55 -0700 (PDT) X-Received: by 10.50.80.78 with SMTP id p14mr331903igx.6.1376091835797; Fri, 09 Aug 2013 16:43:55 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!news.bbs-scene.org!border4.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!fx3no1842084qab.0!news-out.google.com!he10ni1155qab.0!nntp.google.com!fx3no1842083qab.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Fri, 9 Aug 2013 16:43:55 -0700 (PDT) In-Reply-To: <92c32083-74f2-4aaa-94cc-9c9e882bfdf4@googlegroups.com> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=63.80.193.9; posting-account=nD_N8QoAAACgNfe5vMwm0rMAu4pgYumJ NNTP-Posting-Host: 63.80.193.9 References: <87ob96ajv6.fsf@VLAN-3434.student.uu.se> <03ea570b-e45f-4694-ab9b-3413c4770379@googlegroups.com> <878v0aee8i.fsf@VLAN-3434.student.uu.se> <87ob96cxm8.fsf@VLAN-3434.student.uu.se> <92c32083-74f2-4aaa-94cc-9c9e882bfdf4@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: 4 beginner's questions on the PL Ada From: Alan Jump Injection-Date: Fri, 09 Aug 2013 23:43:55 +0000 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Xref: news.eternal-september.org comp.lang.ada:16756 Date: 2013-08-09T16:43:55-07:00 List-Id: 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: >=20 >=20 > X :=3D new Record1; > X :=3D new Record1; > X :=3D new Record1; >=20 > 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 th= at caused something else to point to the record (or to one of its component= s) in between. You can't automatically destroy the record objects if somet= hing else might be pointing to them. >=20 > 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 automatical= ly, but I don't know of any that do. Generally, you have to do your own me= mory 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. =20 >=20 > But there's another factor: if you allocate a task (or a record containin= g a task), using Unchecked_Deallocation (or automatic memory reclamation) w= on'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.=20 >=20 > -- Adam So what you have shown here is a classic recipe for a memory leak. That str= ikes 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 sti= ll tried to avoid reusing variables unless I was absolutely certain that wh= at 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 wou= ld have been to allocate an array of task types, then examine the 'Image(Cu= rrent_Task). But then, if one did produce the array of task types, one woul= d 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 g= oing to need it. - - 73 de N5ILN Alan