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,b99897135d6631cc X-Google-Attributes: gid103376,public Path: g2news1.google.com!news2.google.com!fu-berlin.de!uni-berlin.de!not-for-mail From: "Martin Dowie" Newsgroups: comp.lang.ada Subject: Re: memory management and productivity Date: Mon, 21 Jun 2004 09:02:29 +0100 Organization: BAE SYSTEMS Message-ID: <40d694da$1_1@baen1673807.greenlnk.net> References: <40d15023$1_1@baen1673807.greenlnk.net> <2jnh22F12nvieU2@uni-berlin.de> X-Trace: news.uni-berlin.de NxYfL3MjdH6nY1dbltjk0AdX8SYLXJkW60O/Bp9pn1PI3/MDsO X-Orig-Path: baen1673807.greenlnk.net!baen1673807!not-for-mail X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4807.1700 X-MIMEOLE: Produced By Microsoft MimeOLE V5.50.4807.1700 X-Original-NNTP-Posting-Host: baen1673807.greenlnk.net Xref: g2news1.google.com comp.lang.ada:1727 Date: 2004-06-21T09:02:29+01:00 List-Id: "Jano" wrote in message news:2jnh22F12nvieU2@uni-berlin.de... > It's been so many time since I did C++ that I may be wrong, correct me > in that case. > > IIRC, in C++ you must destroy (delete?) the object to get the destructor > called. So, even if you have a carefully built chain of destructors, if > at some point you forget to destroy the root, you're leaking. > > In Ada, when an object goes out of scope (assuming it has been created > in the stack and not with the "new" operator), it's automatically > finished so you have one less thing to care about. Not quite true! Try this... BTW Jano - are you ever going to make that announcement in cla? ;-) with Ada.Finalization; package Foo is type Bar is private; type Handle is access all Bar; type Reference is access constant Bar; function Default return Bar; private type Bar is new Ada.Finalization.Controlled with null record; procedure Initialize (B : in out Bar); procedure Finalize (B : in out Bar); end Foo; with Ada.Text_IO; use Ada.Text_IO; package body Foo is function Default return Bar is begin return (Ada.Finalization.Controlled with null record); end Default; procedure Finalize (B : in out Bar) is begin Put_Line ("Finalize"); end Finalize; procedure Initialize (B : in out Bar) is begin Put_Line ("Initialize"); end Initialize; end Foo; with Ada.Text_IO; use Ada.Text_IO; with Foo; procedure Wibble is B : Foo.Handle := new Foo.Bar; C : constant Foo.Reference := new Foo.Bar'(Foo.Default); begin Put_Line ("Wibble"); end Wibble;