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-Thread: 103376,ec2a500cce3658c4 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit From: Brian May Newsgroups: comp.lang.ada Subject: Re: Memory leak - What the ...? References: <416d3ca6$0$36214$39cecf19@news.twtelecom.net> Date: Thu, 14 Oct 2004 09:45:33 +1000 Message-ID: User-Agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3 (gnu/linux) Cancel-Lock: sha1:SqeVyJk90oBV7FQfxO2GmbGkkfk= MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii NNTP-Posting-Host: dsl-202-173-153-89.vic.westnet.com.au X-Trace: news.melbourne.pipenetworks.com 1097711120 202.173.153.89 (14 Oct 2004 09:45:20 +1000) X-Complaints-To: abuse@pipenetworks.com X-Abuse-Info: Please forward all headers to enable your complaint to be properly processed. Path: g2news1.google.com!news2.google.com!news.maxwell.syr.edu!news-south.connect.com.au!news.alphalink.com.au!news.melbourne.pipenetworks.com!not-for-mail Xref: g2news1.google.com comp.lang.ada:5172 Date: 2004-10-14T09:45:33+10:00 List-Id: >>>>> "Matthew" == Matthew Heaney writes: Matthew> function Op return CT is begin return CT'(Controlled with Matthew> X => ...); end; Matthew> then the compiler can probably build the return value in Matthew> place: On my system, I get identical results: Adding... (Create)(Adjust)(Finalize)(Finalize)(Adjust)(Finalize)Deleting... (Finalize)(Adjust)Debug Pool info: Total allocated bytes : 36 Total deallocated bytes : 36 Current Water Mark: 0 High Water Mark: 24 (Finalize)(Finalize) curious. -------------------------- What I would have hoped: -------------------------- Adding... (Create)(Finialize)Deleting... (Finalize)(Adjust)Debug Pool info: Total allocated bytes : 36 Total deallocated bytes : 36 Current Water Mark: 0 High Water Mark: 24 (Finalize) Justification: Arr(1) := Create(...); expands into: + Temp := Create(...); -- shallow copy + Finalize(Arr(1)); + Arr(1) := Temp; -- shallow copy Arr(1) := Empty; expands into: + Temp := Empty; -- shallow copy + Finalize(Arr(1)); + Arr(1) := Temp; -- shallow copy + Adjust(Arr(1)) on exit: + Finalize(Arr(1)); As I would have assumed it should be obvious that a deep copy is not required when the original value is going to be finalised. -------------------- What I might expect: -------------------- Adding... (Create)(Finalize)(Adjust)(Finalize)Deleting... (Finalize)(Adjust)Debug Pool info: Total allocated bytes : 36 Total deallocated bytes : 36 Current Water Mark: 0 High Water Mark: 24 (Finalize) Justification: Arr(1) := Create(...) expands into: + Temp := Create(...); -- shallow copy + Finalize(Arr(1)); + Arr(1) := Temp; -- shallow copy + Adjust(Arr(1)); + Finalize(Temp); Arr(1) := Empty expands into: + Temp := Empty; -- shallow copy + Finalize(Arr(1)); + Arr(1) := Temp; -- shallow copy + Adjust(Arr(1)); on exit: + Finalize(Arr(1)); i.e. to answer someone else's question Adjust is required to copy the value, and the original value is no longer required, so it is finalised. ----------- what I got ----------- (Create)(Adjust)(Finalize)(Finalize)(Adjust)(Finalize)Deleting... (Finalize)(Adjust)Debug Pool info: Total allocated bytes : 36 Total deallocated bytes : 36 Current Water Mark: 0 High Water Mark: 24 (Finalize)(Finalize) which leaves "(Adjust)(Finalize)" after create unaccounted for (maybe this is the return statement?). It also leaves the last (Finalize) unaccounted for. This seems very inefficient. -- Brian May