comp.lang.ada
 help / color / mirror / Atom feed
From: "David C. Hoos" <david.c.hoos.sr@ada95.com>
Subject: Re: deallocating class wide types
Date: Sat, 10 May 2003 07:41:48 -0500
Date: 2003-05-10T07:41:48-05:00	[thread overview]
Message-ID: <iq6va.58720$944.57246@fe08.atl2.webusenet.com> (raw)
In-Reply-To: 3ebcea42$1_4@news.arrakis.es


"alfonso acosta" <alfonso_acosta_mail@yahoo.es> wrote in message
news:3ebcea42$1_4@news.arrakis.es...
> hi:
>
> I provide a simplified example of my problem:
>
> package spec:
> ----------------------------------------------------------------
> package My_Class is
>
> type My_Class is abstract tagged null record;
> type My_Class_Access is access all My_Class'Class;
> procedure Destroy (Object: in out My_Class_Access);
>
> end My_Class;
> ----------------------------------------------------------------
>
> first body approach:
> ----------------------------------------------------------------
> with Ada.Unchecked_Deallocation;
> package body My_Class is
> procedure Free is
>     new Ada.Unchecked_Deallocation(Name => My_Class_Access,
>   Object => My_Class'Class);
>
> procedure Destroy (Object: in out My_Class_Access) renames Free;
>
> end My_Class;
> ----------------------------------------------------------------
>
> I get:
> my_class.adb:7:59: subprogram used in renaming_as_body cannot be intrinsic
The error message means exactly what it says -- you cannot rename an
intrinsic subprogram.  If you wish to directly use an instantiation of
Ada.Unchecked_Deallocation, then you must instantiate it in the
package specification -- e.g.

procedure Destroy is
    new Ada.Unchecked_Deallocation(Name => My_Class_Access,
  Object => My_Class'Class);

>
> second approach:
> ----------------------------------------------------------------
> with Ada.Unchecked_Deallocation;
> package body My_Class is
> procedure Free is
>     new Ada.Unchecked_Deallocation(Name => My_Class_Access,
>   Object => My_Class'Class);
>
> procedure Destroy (Object: in out My_Class_Access) is
> begin
>     Free(My_Class_Access);
> end Destroy;
>
> end My_Class;
> ------------------------------------------------------------------
>
> I get:
> my_class.adb:9:09: Invalid use of subtype mark in expression or call
Again, the message means exactly what it says -- you cannot use a type
as the argument in a subprogram call.  You should have written
     Free (Object);
>
> Can someone tell me what Im doing wrong?
> And, should Destroy work with any type which extends My_Class?
The answer is maybe.
If none of the extensions to your class will ever use an access object
as one of its components, it will work.

But if an extension of your class uses access to a type not derived
from Ada.Finalization, then the memory for the object designated by
that access component will be "orphaned" -- i.e. you will have a
"memory leak."
>
> Thanks in advance:
>
> Alfonso Acosta
>
> _______________________________________________
> comp.lang.ada mailing list
> comp.lang.ada@ada.eu.org
> http://ada.eu.org/mailman/listinfo/comp.lang.ada
>
>





  parent reply	other threads:[~2003-05-10 12:41 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-05-10 12:02 deallocating class wide types alfonso acosta
2003-05-10 12:11 ` alfonso acosta
2003-05-10 12:41 ` David C. Hoos [this message]
2003-05-12  0:12 ` Robert I. Eachus
replies disabled

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