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=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,6b353437b73507a5 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews2.google.com!not-for-mail From: anisimkov@yahoo.com (Dmitriy Anisimkov) Newsgroups: comp.lang.ada Subject: Re: Basic program with tasks goes out of memory Date: 6 Aug 2004 21:04:36 -0700 Organization: http://groups.google.com Message-ID: <413e860a.0408062004.6cd54bf9@posting.google.com> References: <5ad0dd8a.0408050655.355fa926@posting.google.com> NNTP-Posting-Host: 195.162.48.71 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: posting.google.com 1091851476 26770 127.0.0.1 (7 Aug 2004 04:04:36 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Sat, 7 Aug 2004 04:04:36 +0000 (UTC) Xref: g2news1.google.com comp.lang.ada:2613 Date: 2004-08-06T21:04:36-07:00 List-Id: wojtek@power.com.pl (Wojtek Narczynski) wrote in message > > Any idea why this program (extracted from AdaSockets example) > eventually eats up all RAM? Runtime leak or my ignorance? I think the only way to do not leak memory on dynamically allocated tasks, is to have a task for deallocate terminated tasks. And each dynamically allocated task have to pass its pointer to the Destructor before termination. The Destructor have to be like that. ------------------------------- task body Destructor is Rf : Relay_Access; procedure Free is new Ada.Unchecked_Deallocation (Relay, Relay_Access); begin loop select accept Free_Task (R : Relay_Access) do Rf := R; end Free_Task; end select; loop exit when Rf'Terminated; delay 0.001; end loop; Free (Rf); end loop; exception when E : others => Unexpected (E, "Destructor"); end Destructor; ------------------------- The complete application with task Destructor usage is in the http://www.ada-ru.org/src/relay.adb It has a same as tcprelay.adb (from AdaSockets) functionality, but with dynamically created task deallocation. It would be good to have a method to wait until task termination like on entry call. Maybe something like that. ---------------------------------- task body Destructor is Rf : Relay_Access; procedure Free is new Ada.Unchecked_Deallocation (Relay, Relay_Access); begin loop select accept Free_Task (R : Relay_Access) do Rf := R; end Free_Task; end select; select Rf'Wait_Termination; or delay 10.0; -- Could not wait more. null; end loop; Free (Rf); end loop; exception when E : others => Unexpected (E, "Destructor"); end Destructor; -------------------------