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 Date: Thu, 10 May 2007 00:00:40 +0200 From: Manuel Collado User-Agent: Thunderbird 1.5.0.7 (Windows/20060909) MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Finalization of static package variables References: <4640f20b$1@news.upm.es> <1178723724.958486.24820@u30g2000hsc.googlegroups.com> In-Reply-To: <1178723724.958486.24820@u30g2000hsc.googlegroups.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit NNTP-Posting-Host: 138.100.242.205 Message-ID: <464244d8$1@news.upm.es> X-Trace: news.upm.es 1178748120 138.100.242.205 (10 May 2007 00:02:00 +0200) Path: g2news1.google.com!news3.google.com!proxad.net!213.200.89.82.MISMATCH!tiscali!newsfeed1.ip.tiscali.net!news.tiscali.de!news.belwue.de!kanaga.switch.ch!switch.ch!news.rediris.es!news.upm.es!not-for-mail Xref: g2news1.google.com comp.lang.ada:15697 Date: 2007-05-10T00:00:40+02:00 List-Id: Adam Beneschan escribi�: > On May 9, 1:20 am, Stephen Leake > wrote: >> 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? Using JEWL-1.6, last updated for GNAT-3.15p. Unable to use it with GPS200x (until now - probably some required libraries not properly installed). >> >>> 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. > > Except that Manuel never said he was using tasks. I'm envisioning > that he probably has a controlled object whose initialization causes > some Windows process to be spawned (either directly or via some > function in some other GUI library), and finalization causes the > process to be terminated. Well, JEWL uses tasks internally. So, who knows... > >> 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. > > No, I believe that all objects, including static package variables > *and* including allocated objects that have not yet been deallocated, > are supposed to be finalized when the environment task completes. > 10.2(25), 7.6.1(10). The fact is that there is a significant difference in behaviour between variables in the main procedure and static package variables. Example: 1. The following code always terminates smoothly. --- main1.adb --------------------------------------- with Jewl.Simple_Windows; use Jewl.Simple_Windows; procedure Main1 is My_Frame: Frame_Type := Frame (200, 100, "Frame 1", 'Q'); Ok: Button_Type := Button (My_Frame, (50, 20), 80, 25, "OK", 'Q'); C: Character; begin C := Next_Command; -- just wait for any 'frame' event end Main1; ---------------------------------------------------- 2. The following alternate code may not terminate (remains as a zombie process). Requires explicit termination of the Frame, either by the [X] at the top-rigth corner or by 'Close(My_Frame)'. --- main2.adb --------------------------------------- procedure Main2 is begin Do_Frame; -- just wait for any GUI event end Main2; --- pkg_frame.ads --------------------------------------- package Pkg_Frame is procedure Do_Frame; end Pkg_Frame; --- main1.adb --------------------------------------- with Jewl.Simple_Windows; use Jewl.Simple_Windows; package body Pkg_Frame is My_Frame: Frame_Type := Frame (200, 100, "Frame 2", 'Q'); Ok: Button_Type := Button (My_Frame, (50, 20), 80, 25, "OK", 'Q'); C: Character; procedure Do_Frame is begin C := Next_Command; -- just wait for any GUI event -- POSSIBLE IMPROPER TERMINATION -- -- may be fixed by enabling the following statement -- Close (My_Frame); end Do_Frame; end Pkg_Frame; ---------------------------------------------------- Could the My_Frame declaration scope interfere with possible unterminated tasks inside JEWL? Regards. -- Manuel Collado - http://lml.ls.fi.upm.es/~mcollado