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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,26639dcc06d45917 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-10-22 07:38:15 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!sn-xit-05!sn-xit-06!sn-post-02!sn-post-01!supernews.com!corp.supernews.com!not-for-mail From: "Matthew Heaney" Newsgroups: comp.lang.ada Subject: Re: Array of unbounded strings, memory leakage? Date: Tue, 22 Oct 2002 10:36:28 -0400 Organization: Posted via Supernews, http://www.supernews.com Message-ID: References: X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2720.3000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 X-Complaints-To: abuse@supernews.com Xref: archiver1.google.com comp.lang.ada:30030 Date: 2002-10-22T10:36:28-04:00 List-Id: "Eric G. Miller" wrote in message news:pan.2002.10.20.16.23.48.564315@jps-nospam.net... > I know the following isn't terribly efficient, but does the Resize > procedure leak memory? Instances of Unbounded_String --even if they are components of an array-- don't leak memory. Typically they would be implemented as a private derivation from Controlled. Of course, if you allocate the array on the heap, and then forget to deallocate the array, then of course that is a memory leak. Programmers sometimes forget (or perhaps don't even realize) that Unchecked_Deallocation is "aware" that the object being deallocating is Controlled, and Finalization will occur before the actual memory reclaimation happens. This is not unlike how delete works in C++: the dtor will get invoked prior to actual deallocation. The Charles library already has an unbounded vector you could use, instead of manipulating unbounded arrays directly. For example: package Unbounded_String_Vectors is new Charles.Vectors.Unbounded (Unbounded_String); use Unbounded_String_Vectors; V : Container_Type; ... Resize (V, Size => N); --or-- Assign (V, Length => N); --or-- Assign (V, Length => N, Item => Null_Unbounded_String); The Charles vector differentiates between "length" and "size". It wasn't clear from your example whether the length or size needed modification, so the fragment above shows you how to do both. http://home.earthlink.net/~matthewjheaney/charles/charles-vectors-unbounded. html I just released a new version (20021021) of the library, with better error checking. http://home.earthlink.net/~matthewjheaney/charles/index.html