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=0.2 required=5.0 tests=BAYES_00,INVALID_MSGID, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,3498dd887729ed19 X-Google-Attributes: gid103376,public From: Jonas Nygren Subject: Re: Garbage Collection in Ada Date: 1996/10/31 Message-ID: <3278C69B.310F@ehs.ericsson.se>#1/1 X-Deja-AN: 193645160 references: <01bbc6a3$4cf03480$829d6482@joy.ericsson.se> content-type: text/plain; charset=us-ascii organization: Ericsson Hewlett-Packard Telecommunications AB mime-version: 1.0 reply-to: ehsjony@ehs.ericsson.se newsgroups: comp.lang.ada x-mailer: Mozilla 3.0 (WinNT; I) Date: 1996-10-31T00:00:00+00:00 List-Id: Mitch Gart wrote: Jonas Nygren (ehsjony@ehs.ericsson.se) wrote: (snip) : package Collected is : type Object is : tagged record : Reference_Count : Natural; : end record; : type Object_Access is access all Object'Class; : type Handle is new Ada.Finalization with : record : Ref : Object_Access; : end record; : end Collected; (snip) This suffers from several problems: - If you provide a function to do allocations, function Allocate_Obj return Handle; and users use this function, things work well, but if a user calls "new Object" directly things don't work at all. - Obj1 := Obj2; doesn't work because the reference count value is copied. If Obj2's count is 3 before the assignment, after the assignment Obj1's count is also 3 which is probably wrong. Mitch, you are quite correct. The Object part should be in the private part of the package and only Handle and its derivatives should be in the visible part. This have the effect that type extension can only be done in child packages. Pehaps I should have shown that too in my example but I thought it might have caused information overload. By requiring type extension in child packages one lose the capability of hiding implementation of the parent implementation for the derived type. I think this just serves to strengthen the argumentation in favor for GC in Ada. /jonas