From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5367 invoked by alias); 5 Feb 2011 00:22:58 -0000 Received: (qmail 5356 invoked by uid 22791); 5 Feb 2011 00:22:51 -0000 X-SWARE-Spam-Status: No, hits=-1.6 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,SPF_HELO_PASS,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from smtp-out.google.com (HELO smtp-out.google.com) (216.239.44.51) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sat, 05 Feb 2011 00:22:46 +0000 Received: from wpaz13.hot.corp.google.com (wpaz13.hot.corp.google.com [172.24.198.77]) by smtp-out.google.com with ESMTP id p150Mgp6029930 for ; Fri, 4 Feb 2011 16:22:42 -0800 Received: from pxi9 (pxi9.prod.google.com [10.243.27.9]) by wpaz13.hot.corp.google.com with ESMTP id p150MeoU008389 (version=TLSv1/SSLv3 cipher=RC4-MD5 bits=128 verify=NOT) for ; Fri, 4 Feb 2011 16:22:41 -0800 Received: by pxi9 with SMTP id 9so504509pxi.9 for ; Fri, 04 Feb 2011 16:22:40 -0800 (PST) MIME-Version: 1.0 Received: by 10.143.41.4 with SMTP id t4mr8022564wfj.310.1296865360291; Fri, 04 Feb 2011 16:22:40 -0800 (PST) Received: by 10.142.50.3 with HTTP; Fri, 4 Feb 2011 16:22:39 -0800 (PST) In-Reply-To: <20110204194604.GB12837@nibiru.local> References: <20110204194604.GB12837@nibiru.local> Date: Sat, 05 Feb 2011 04:25:00 -0000 Message-ID: Subject: Re: C++ and garbage collection From: Lawrence Crowl To: weigelt@metux.de, gcc-help@gcc.gnu.org Content-Type: text/plain; charset=ISO-8859-1 X-System-Of-Record: true X-IsSubscribed: yes Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org X-SW-Source: 2011-02/txt/msg00113.txt.bz2 On 2/4/11, Enrico Weigelt wrote: > I'm currently working on an complex C++ application (which I, if it > would have to be rewritten from scratch, would do in Java instead ;-o) > and I wonder whether it's possible to move to an garbage collection > in smaller steps. For now there're some parts using some "autopointer" > class (didn't deeply look into it, but I guess it's overloading > the pointer operations and doing some reference counting, which > of course isn't generally complete - would keep ring structures > forever ;-o). > > My idea is to add some mark+sweep gc (boem-gc ?) and remove (or > somehow disable) all delete operations. Does that work safely, > or do I have to cope with certain nasty side effects ? If your problem is leaking memory, and you aren't playing games with your pointers, then you can just add in the Boehm collector, leaving the deletes in place. This approach will leave the program working pretty much as before, but with less memory. If your problem is using objects after you have freed them, then you have a much harder problem. Many C++ programs do real work in the destructors (like closing files) and removing the delete operations would disable that code. One viable approach is to modify the uses of pointers into shared_ptr (from TR1 or boost) and then add the Boehm collector. This process takes work, because changing all pointers won't work and changing none won't buy you anything. -- Lawrence Crowl