Re: C++ and garbage collection

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 2/4/11, Enrico Weigelt <weigelt@xxxxxxxx> 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


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux