comp.lang.ada
 help / color / mirror / Atom feed
From: "Luke A. Guest" <laguest@n_o_p_o_r_k_a_n_d_h_a_m.abyss2.demon.co.uk>
Subject: Re: Problems with controlled types, gnatmem thinks handle is leaking memory (long)
Date: Sun, 20 Feb 2005 23:09:15 +0000
Date: 2005-02-20T23:09:15+00:00	[thread overview]
Message-ID: <pan.2005.02.20.23.09.14.990226@n_o_p_o_r_k_a_n_d_h_a_m.abyss2.demon.co.uk> (raw)
In-Reply-To: 1s73d5wqz8pme.1m22aqftdn6ij.dlg@40tude.net

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.




  reply	other threads:[~2005-02-20 23:09 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-02-20 16:30 Problems with controlled types, gnatmem thinks handle is leaking memory (long) Luke A. Guest
2005-02-20 18:09 ` Dmitry A. Kazakov
2005-02-20 23:09   ` Luke A. Guest [this message]
2005-02-21  8:49     ` Dmitry A. Kazakov
2005-02-21 20:12     ` Simon Wright
2005-02-21 20:54       ` Dmitry A. Kazakov
2005-02-21 20:59         ` Robert A Duff
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox