Re[2]: [Gc] Re: Boehm GC problem

Ivan Maidanski <ivmai-JGs/[email protected]>
Newsgroups gmane.comp.programming.garbage-collection.boehmgc
Message-ID <[email protected]>
 Hi Bruce and Vadim,

You are right about guarantees. But as I understood the code just a test case showing that all objects of particular type are not collected by GC (on Vadim's target).

Regards,
Ivan


San, 29 Dec 2013, 12:36 +13:00 from Bruce Hoult <[email protected]>:
>This seems like very bad code to me -- and a bad idea.
>
>If you need cleanup for all or most of your objects then a tracing GC is probably the wrong way to manage them. You might as well use some reference-counting or pool approach.
>
>This is advisable from an efficiency point of view, but it is mandatory if you REQUIRE that the cleanup from every object is guaranteed to be run.
>
>GCs in general do not guarantee to find every inaccessible object on every GC. The documentation for gc_cleanup in gc_cpp.h make it clear that BDWGC in particular does not make a guarantee.
>
>Most systems with GC don't run the GC on program exit. And nor should they. It's usually a waste of time. But even if you trigger a manual GC there is no guarantee that all cleanup functions will be run. Not even if you call it two or three times.
>
>If you really need to have a guarantee that cleanup is run for every object, including objects that still exist at program exit, and you want to use GC (any GC, not just this one) then what you have to do is:
>
>1) add objects requiring cleanup to a global collection (list, hash table etc) that is NOT scanned by the GC.
>2) at program exit call cleanup yourself for every object in that collection.
>3) add a finaliser to each cleanup object that removes the object from the global collection and then calls the cleanup function.
>
>I've done this in shipping code and it works. Every time.
>
>
>
>On Sun, Dec 29, 2013 at 10:20 AM, Ivan Maidanski  < [email protected] > wrote:
>>Hi Vadim,
>>
>>It is better to send questions to the ML ( [email protected] ). Probably someone on the list knows the answer.
>>
>>I have tried your sample but it worked for me (on cygwin), the output:
>>1000
>>1
>>
>>1001
>>1
>>
>>Just for reference, I used the recent BDWGC snapshot and following commands to build the sample:
>>gcc -I include -c extra/gc.c
>>g++ -I include test_app.cpp gc.o 
>>
>>[Translated] Fri, 27 Dec 2013, 16:51 +04:00 from Vadim < [email protected] >:
>>>Hi.
>>>I have an issue with Boehm GC, probably you could help me.
>>>I found the solution  http://www.drdobbs.com/the-boehm-collector-for-c-and-c/184401632?pgno=6 how to use the collector for the std types but it does not work for me.
>>>
>>>The code:
>>>
>>>#include "app.h" I replaced it to:
>>#include <iostream>
>>#include <stdlib.h>
>>#include "gc_cpp.h"
>>
>>>
>>>using namespace std;
>>>
>>>long allocated = 0;
>>>
>>>template<class Super>
>>>class Boehmable : public Super, public virtual gc_cleanup
>>>{
>>>public:
>>>Boehmable() : Super(), gc_cleanup() { allocated++; }
>>>virtual ~Boehmable() { allocated--; }
>>>};
>>>
>>>class MyClass
>>>{
>>>public:
>>>MyClass() {};
>>>~MyClass() {};
>>>};
>>>
>>>int main(int argc, char **argv)
>>>{
>>>for (int i = 0; i < 1000; i++)
>>>{
>>>new Boehmable<MyClass>();
>>>}
>>>
>>>cout << allocated << endl;    // 1000
>>>GC_gcollect();
>>>cout << allocated << endl << endl;  // 1 - It works 
>>>
>>>for (int i = 0; i < 1000; i++)
>>>{
>>>new Boehmable<string>();
>>>}
>>>
>>>cout << allocated << endl;    // 1001
>>>GC_gcollect();
>>>cout << allocated << endl << endl;  // 1001 - Does not work!
>>>
>>>system("pause");
>>>
>>>return 0;
>>>}
>>>
>>>Does not work for list, vector, etc. types neither.
>>Regards,
>>Ivan
>>
>>-- 
>>This message has been scanned for viruses and
>>dangerous content by MailScanner , and is
>>believed to be clean.
>>_______________________________________________
>>Gc mailing list
>>[email protected]
>>http://www.hpl.hp.com/hosted/linux/mail-archives/gc/
>
>_______________________________________________
>Gc mailing list
>[email protected]
>http://www.hpl.hp.com/hosted/linux/mail-archives/gc/


-- 
Иван Майданский

_______________________________________________
Gc mailing list
Gc-V9/[email protected]
http://www.hpl.hp.com/hosted/linux/mail-archives/gc/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.