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=-2.9 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI autolearn=unavailable autolearn_force=no version=3.4.4 X-Google-Thread: 103376,ec2a500cce3658c4 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII Path: g2news1.google.com!news1.google.com!newsfeed.stanford.edu!newsmi-us.news.garr.it!NewsITBone-GARR!news.mailgate.org!newsfeed.stueberl.de!teaser.fr!enst.fr!melchior!cuivre.fr.eu.org!melchior.frmug.org!not-for-mail From: Stephen Leake Newsgroups: comp.lang.ada Subject: Re: Memory leak - What the ...? Date: 12 Oct 2004 20:07:40 -0400 Organization: Cuivre, Argent, Or Message-ID: References: <416BAFA4.7020400@netcabo.pt> NNTP-Posting-Host: lovelace.ada-france.org Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: melchior.cuivre.fr.eu.org 1097626082 16605 212.85.156.195 (13 Oct 2004 00:08:02 GMT) X-Complaints-To: usenet@melchior.cuivre.fr.eu.org NNTP-Posting-Date: Wed, 13 Oct 2004 00:08:02 +0000 (UTC) To: comp.lang.ada@ada-france.org Return-Path: In-Reply-To: <416BAFA4.7020400@netcabo.pt> User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3 X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at ada-france.org X-BeenThere: comp.lang.ada@ada-france.org X-Mailman-Version: 2.1.4 Precedence: list List-Id: "Gateway to the comp.lang.ada Usenet newsgroup" List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Xref: g2news1.google.com comp.lang.ada:5112 Date: 2004-10-12T20:07:40-04:00 Marius Amado Alves writes: > Jean-Pierre Rosen wrote: >=20 > > Brian May a =E9crit : > > > >> Why does 1 create result in 2 adjusts and 3 finalize? > >> (I would have expected number of adjust =3D=3D number of finalize =3D= =3D 1) > >> > >> Why are there 2 finalize at the end? > >> (I would have expected 1 maximum) > >> > >> Is there anyway of making this code more efficient? > >> (It seems to me that a deep copy for a create operation just causes > >> heap fragmentation with no real benefit.) > > The magic formula is: > > Number_Of_Finalize =3D Number_Of_Initialize + Number_Of_Adjust + > > Number_Of_Aggregates > > Remember that aggregates are objects which have no initialize (they > > are supposed to be created correctly). They are finalized, though. >=20 > One of the areas where Ada is absolutely counter-intuitive and > troublesome :-( What would you consider "intuitive" in the area of Ada.Controlled? "intuitive" means "something known without learning". How can you expect anyone to know how Ada.Controlled works without learning it? I suspect you actually mean "not like anything else I know". Well, yes! > Controledness in Ada is a bowl of spagetti. No, I think it's more like a mildly complex electronics schematic. Confusing at first, but wonderfully powerful and functional once you understand it. > I still lack an understandable explanation of why this does not > leak: >=20 > if This.Data /=3D null then > This.Data :=3D new Stream_Element_Array'(This.Data.all); > end if; When this code is called (in Adjust), This.Data is a _copy_ of a pointer (the copy is made by the initial object copy done before Adjust is called). The assignment throws away the copy of the pointer, and replaces it with a pointer to a copy of the data. The original copy of the original pointer is still in the original object, and will be finalized. --=20 -- Stephe