Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Garbage Collection

This topic is 5303 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

First of all, I''m not trying to start a ''to GC or not to GC'' type of flame war! What I''m interested in knowing is, has anyone tried using the Hans Boehm conservative garbage collector in anger? I''m just about to start coding something that does a lot of graph analysis type of things & I''m expecting to end up with fairly huge numbers of cyclic references etc so want an effective way of easily (& preferably) managing object lifetimes especially as when researching the algorithms I intend to use I realised that ther will be a lot of adding & removing reference to objects. Basically I figured that the easiest way out would be to do garbage collection, especially given that the HB GC is apparently only 27% slower than doing it by hand (for the memory allocation related operations, not the whole program...) + it obviously reduces the complexity. I''ve played a little bit with the GC, but I haven''t yet been able to figure a few things out;
  • No objects derived from ''gc'' seem to run their destructors...I noticed that in the sample all the classes derived from gc contained simple data types that wouldn''t care if the d''tor wasn''t run (ints for example) - although my d''tor seemed to be run normally when I derived from ''gc_cleanup''
  • How can I ensure all inactive objects are deallocated? GC_gcollect(); ?
  • Do I actually need to call GC_init() usually?
  • I saw a note to the effect that arrays of objects would delete properly under some conditions, the example they gave used ''delete'' rather than ''delete[]''...would ''delete[]'' have the same problem?
  • Do I need to do something to shut down the GC (as in inverse of GC_init() )?
  • do I always need to call new like this: ''A* a = new(UseGC) A(bob);''
Other than that, it seems quite neat! I think its definatelly worth looking at if you''re trying to do something complex. Out of interest, are there any other GC libraries anyone would suggest looking at?

Share this post

Link to post
Share on other sites

I''m pretty sure you can set up the Boehm GC to call destructors, but it''s not automatic.

Have you considered doing without destructors? Usually, you can do without. Do your destructors do anything but free memory anyhow?

- Josh

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!