This question already has an answer here:
- Is garbage collection necessary? [duplicate] 10 answers
A lot of languages like Java and C# have garbage collectors that free memory when that memory no longer has any reference. Yet they don't immediately free it after the reference counter hits zero but instead every once in a while they check on all the memory to see if that memory has any reference and delete it if it doesn't. What is the benefit of doing that way?
The downside to doing it that way is that you lose the destructor as you can't guarantee when it will be called.
I would imagine that it is done that way because of performance, but has there been any study that shows that a garbage collector that works like that has a better performance then
std::shared_ptr found in C++?