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,edd7ea1b2d7e9a18 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-02-13 11:32:48 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.fjserv.net!nntp.theplanet.net!inewsm1.nntp.theplanet.net!zen.net.uk!news.cabal.org.uk!news-peer.gradwell.net!not-for-mail Mime-Version: 1.0 X-Newsreader: knews 1.0b.1 References: From: porton@ex-code.com (Victor Porton) Subject: Re: Pitfall: freeing access discriminants Newsgroups: comp.lang.ada Content-Type: text/plain; charset=us-ascii Message-ID: Date: Fri, 14 Feb 2003 00:24:41 +0500 Organization: Extreme Code Software (http://ex-code.com) X-URL: http://www.ex-code.com/ NNTP-Posting-Date: 13 Feb 2003 19:32:47 GMT NNTP-Posting-Host: 195.149.39.13 X-Trace: 1045164767 news.gradwell.net 344 mail2news/195.149.39.13 X-Complaints-To: news-abuse@gradwell.net Xref: archiver1.google.com comp.lang.ada:34069 Date: 2003-02-13T19:32:47+00:00 List-Id: In article , Stephen Leake writes: > porton@ex-code.com (Victor Porton) writes: > >> type Integer_Access is access Integer; >> >> type T(D: access Integer) is Ada.Limited_Controlled with null record; >> >> procedure Finalize(Object: in out T) is >> -- Error: cannot convert access discriminant to non-local access type >> D: Integer_Access := Integer_Access(Object.D); >> begin >> Free(D); >> end; >> >> What to do? It seems being a serious deficiency in Ada or there are a >> workaround? > > Why would you ever want to free an access discriminant? I usually use > them to point to a constant object. > > One good rule for dynamic memory allocation; never free something you > did not allocate. Just X: T(new Integer'(12)); -- The real example is more natural -- than allocating an integer. However I realized that Ada access discriminants are not to be used in such the way as this causes a great non-reliability. I switched to just record memebers of an access type.