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.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 Path: border1.nntp.ams3.giganews.com!border2.nntp.ams3.giganews.com!border2.nntp.ams2.giganews.com!border4.nntp.ams.giganews.com!border2.nntp.ams.giganews.com!nntp.giganews.com!rt.uk.eu.org!aioe.org!.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Reference counting and idempotent finalize Date: Thu, 12 Sep 2013 09:33:15 +0200 Organization: cbb software GmbH Message-ID: References: <5rbmj2y8ml2b$.e0ygtir1g3mt$.dlg@40tude.net> Reply-To: mailbox@dmitry-kazakov.de NNTP-Posting-Host: IenaDxMXK2hi7fvYcb+MlQ.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: 40tude_Dialog/2.0.15.1 X-Notice: Filtered by postfilter v. 0.8.2 X-Original-Bytes: 2473 Date: 2013-09-12T09:33:15+02:00 List-Id: On Thu, 12 Sep 2013 05:34:53 +0000 (UTC), Natasha Kerensikova wrote: > On 2013-09-11, Dmitry A. Kazakov wrote: >> You could make an alternative version for debug scenario which keeps track >> of all changes of the reference count dumping them on errors. GNAT stack >> trace is handy for that. Do not trust reference counting, it is an endless >> source of many hideous errors even if the implementation of is correct. > > Would you please elaborate on why reference counting shouldn't be > trusted? What dangers am I brazingly exposing myself to? Because reference counting scheme (and any GC in general) is based on certain premises to work. These are always difficult to satisfy in a real-life application. In particular, one that you have no circular dependencies. The typical approach of breaking them (when you cannot redesign it otherwise) is having weak references in addition to strong ones. Consider a tree of nodes where parents refer to children and children do to the parent. One reference is strong, a backward one must be weak. That adds another layer of complexity to already messy thing. The point is actually that problems come from the application domain. So, time to time, you will have to inspect reference counts even if counting implementation as such is all OK. Thus it is better to integrate some tools for this right from the start. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de