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,FREEMAIL_FROM, 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-7-bit Path: g2news1.google.com!news1.google.com!newshub.sdsu.edu!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed.stueberl.de!proxad.net!usenet-fr.net!enst.fr!melchior!cuivre.fr.eu.org!melchior.frmug.org!not-for-mail From: Marius Amado Alves Newsgroups: comp.lang.ada Subject: Re: Memory leak - What the ...? Date: Tue, 12 Oct 2004 17:05:42 +0100 Organization: Cuivre, Argent, Or Message-ID: References: NNTP-Posting-Host: lovelace.ada-france.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Trace: melchior.cuivre.fr.eu.org 1097597147 22145 212.85.156.195 (12 Oct 2004 16:05:47 GMT) X-Complaints-To: usenet@melchior.cuivre.fr.eu.org NNTP-Posting-Date: Tue, 12 Oct 2004 16:05:47 +0000 (UTC) To: comp.lang.ada@ada-france.org Return-Path: User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax) X-Accept-Language: en-us, en In-Reply-To: X-OriginalArrivalTime: 12 Oct 2004 16:05:31.0676 (UTC) FILETIME=[4CA4FDC0:01C4B075] 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:5099 Date: 2004-10-12T17:05:42+01:00 >>I still lack an understandable explanation of why this does not leak: >> >> if This.Data /= null then >> This.Data := new Stream_Element_Array'(This.Data.all); >> end if; > > Adjust is called just after the members of the record have been > copied. So imagine you have > > A := B; > > When Adjust(A) gets called, you will have > > A.Data = B.Data > > Since Data is an access type, you have a shallow copy where both A and > B have members pointing to the same heap space. > > In the Adjust, what A does is replicate the pointed data to get a new > pointer and a deep copy where A and B point to different heap copies. > > Additionally, before A being overwritten, Finalize(A) is called just > in case it needs to free some memory. > > Hope this helps. Not really. The only way for leaking not to take place is for the old This.Data value being held somewhere. Where? Or for Finalize (A) to be called before Adjust, but then This.Data should become null, no? And then the if condition would never hold. The alternative being This.Data pointing to garbage.