C ++ garbage collector

I tried to create a garbage collector in C ++, I developed it as a base class for all mine called garbageCandidate, which contains a static vector containing pointers to garbageCandidate, with each instance of garbageCollector with clicking "this" on the vector.

Then a static function appears and all pointers in the static vector are deleted.

At the very beginning of the delete function (delete with the first pointer) I get an error message in which the delete was used on an invalid pointer ...

Is this related to static / dynamic binding? I mean: the delete operator cannot act as expected, since I call delete in the father class, and is it really a child?

Can this be avoided to create virtual destructors? (or virtual delete function)?

or am I missing something?

ps: all objects used for the test, where they are created dynamically.

+5
source share
2 answers

Is there a reason you are collecting your own garbage collector? If all your objects are created dynamically, then why don't you use raising smart pointers (like boost :: shared_ptr ), which essentially uses RAII to give you a well-tested garbage collection solution?

, , ( , ). , ?

0

, GC, , Boehm Conservative GC . :

, GC Boehm Smart- , .

0

All Articles