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,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,c68551ab190372c8 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!news.glorb.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!wn14feed!worldnet.att.net!attbi_s53.POSTED!53ab2750!not-for-mail From: "Jeff C r e e.m" Newsgroups: comp.lang.ada References: Subject: Re: Ada memory management? X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.2180 X-RFC2646: Format=Flowed; Original X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 Message-ID: NNTP-Posting-Host: 24.147.74.171 X-Complaints-To: abuse@comcast.net X-Trace: attbi_s53 1097147829 24.147.74.171 (Thu, 07 Oct 2004 11:17:09 GMT) NNTP-Posting-Date: Thu, 07 Oct 2004 11:17:09 GMT Organization: Comcast Online Date: Thu, 07 Oct 2004 11:17:10 GMT Xref: g2news1.google.com comp.lang.ada:4864 Date: 2004-10-07T11:17:10+00:00 List-Id: "Stephen Thomas" wrote in message news:pan.2004.10.07.10.41.56.495730@stephenthomas.uklinux.net... > On Thu, 07 Oct 2004 12:00:42 +0200, Christoph Karl Walter Grein wrote: > >> procedure Does_This_Leak is >> type Int_Ptr is access Integer; >> ptr: Int_Ptr; >> begin >> ptr := new Integer; >> end Does_This_Leak; >> >> Of course this leaks, and imagine how much! > > Actually, no it shouldn't, not on a halfway-decent implementation. > Logically speaking, a storage pool for items accessed via values of > an access type has the same lifetime as the access type itself. In > the above example, a new storage pool for Int_Ptr is created on > entry to Does_This_Leak, and is removed on exit. > > Stephen > -- Stephen is correct...But just to be clear (because this is where people (not Stephen) get confused is that the following (much more common construct) would leak unless unchecked_deallocation is used. package body Like_A_Sieve is type Int_Ptr is access Integer; procedure Does_This_Leak is ptr: Int_Ptr; begin ptr := new Integer; end Does_This_Leak; end Like_A_Sieve; It is a rare (though still useful) construct to be able to get away with having the pointer type declaration totally within a short lived procedure. Sieve