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,714a9fe4718c9803 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!proxad.net!proxad.net!194.117.148.138.MISMATCH!pe2.news.blueyonder.co.uk!blueyonder!peer-uk.news.demon.net!kibo.news.demon.net!news.demon.co.uk!demon!not-for-mail From: "Luke A. Guest" Newsgroups: comp.lang.ada Subject: Re: Problems with controlled types, gnatmem thinks handle is leaking memory (long) Date: Sun, 20 Feb 2005 23:09:15 +0000 Message-ID: References: <1s73d5wqz8pme.1m22aqftdn6ij.dlg@40tude.net> NNTP-Posting-Host: abyss2.demon.co.uk Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: news.demon.co.uk 1108940955 28619 62.49.62.197 (20 Feb 2005 23:09:15 GMT) X-Complaints-To: abuse@demon.net NNTP-Posting-Date: Sun, 20 Feb 2005 23:09:15 +0000 (UTC) User-Agent: Pan/0.14.2 (This is not a psychotic episode. It's a cleansing moment of clarity.) Xref: g2news1.google.com comp.lang.ada:8434 Date: 2005-02-20T23:09:15+00:00 List-Id: On Sun, 20 Feb 2005 19:09:02 +0100, Dmitry A. Kazakov wrote: > The code does not much differ in implementation from mine > (http://www.dmitry-kazakov.de/ada/components.htm). I'll have a look at this, thanks. > Minor comments: > > In Finalize: I check if Ref_Count = 0 before decrementing and raise No need to check for the reference count to be 0, as it can never go negative and if it does, there's a problem with the code. > Program_Error rather than Constraint_Error. When you call Ok,but I'm not raising any exceptions here. > Unchecked_Dellocation it sets the pointer to null. You don't need to do Fair enough, I can remove that then ;-) > that again. I also have the pointed objects limited controlled and check Well, my pointed to objects are limited controlled, so I only ever return the reference to the object. I don't ever want to copy the pointer, just the handle around it. > if the Ref_Count is zero upon object's finalization. That helps a lot! I suppose I could raise an exception if the reference count isn't zero on finalisation, hmmm...but surely there would be an error in the code if that were not the case? Surely it's another example of what I mentioned above, it should never go wrong as long as the initialize, adjust & finalize subprograms have been implemented correctly. > Especially if you mistakenly create circular dependencies in the > objects. (The compiler will finalize them anyway so you'll get an > exception) Well, considering Ada95 compilers have trouble with circular packages, I can't see me having any trouble considering I have only one major type per package. [Missing extra annotations] Thanks for the extra annotations, they were really helpful. I think it's a problem with gnatmem, which is a problem considering that gcc-3.4.x and above doesn't have a gnatmem at all and valgrind doesn't work with anything I compile with gnat (I haven't tried gcc-3.4.x yet). > Everything seems OK to me. > > You can make Handle_Type controlled add Initialize and Finalize to see > when they are called. Handle_Type.Finalize should be called *before* the > text > > Finalize: Deallocated memory > > Otherwise, if you really had a leak, it would be called after that. (The > list of all controlled objects is maintained at run-time.) Good, point, I'll try it out and see what happens. Thanks, Luke.