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 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,ee06257af909a235 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!out03b.usenetserver.com!news.usenetserver.com!in04.usenetserver.com!news.usenetserver.com!uns-out.usenetserver.com!news.usenetserver.com!pc02.usenetserver.com!news.flashnewsgroups.com-b7.4zTQh5tI3A!not-for-mail Newsgroups: comp.lang.ada Subject: Re: Finalization of static package variables References: <4640f20b$1@news.upm.es> From: Stephen Leake Date: Wed, 09 May 2007 04:20:44 -0400 Message-ID: User-Agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3 (windows-nt) Cancel-Lock: sha1:VaIMRJpQV0l4BLYIzMCci+3yUEo= MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Complaints-To: abuse@flashnewsgroups.com Organization: FlashNewsgroups.com X-Trace: d62b14641846c759e00d413131 Xref: g2news1.google.com comp.lang.ada:15672 Date: 2007-05-09T04:20:44-04:00 List-Id: Manuel Collado writes: > Variables declared in the global scope of a package body seem not to > be finalized automatically at the end of the whole program (using GNAT > 3.15p on WindowsXP). Is there some reason you are not using a more current version of GNAT? > If some of these variables contain certain GUI stuff, the program > remains as a zombie process after the main procedure termination. Technically, that cannot be true; the "main procedure" is the "environment task", and it does not "terminate" (in the Ada definition of that word) until all of the tasks it has spawned have "terminated". I think that what you are saying is that there are some tasks that have not terminated when the main procedure is ready to terminate, and that in fact those tasks never terminate. > After several trial-and-error attemps, an Unchecked_Deallocation on > these variables seems to do the trick (the whole program terminates > smoothly). Unchecked_Deallocation is used on access variables (aka "pointers"). Such variables are _not_ automatically finalized by Ada; calling Unchecked_Deallocation is the standard-compliant way to finalize them. > But this is probably not standard-conformant (ARM 13.11.2-16). This paragraph says: Evaluating a name that denotes a nonexistent object is erroneous. The execution of a call to an instance of Unchecked_Deallocation is erroneous if the object was created other than by an allocator for an access type whose pool is Name'Storage_Pool. I don't see how that is relevant to your problem. What version of the ARM are you quoting? When you say "ARM" without a year, it implies "current" which means "Ada 2007" (or, informally, "Ada 2005"). > If there a standard way of forcing finalization of static package > variables at program termination? I.e., without declaring them as > dynamic, or inside a main procedure, or calling explicitly the > finalization actions. If the type of the variable is derived from Ada.Finalization.Controlled or Limited_Controlled, it will be finalized when it goes out of scope. Otherwise, it won't be. However, a static package variable never goes out of scope, so that is no help. Calling Unchecked_Deallocation does seem to be the correct approach to what you need to do. Why is it a problem? Posting code that outlines what you are doing would help a lot. -- -- Stephe