3 ms·
Reference counting is not a complete GC solution, it does not collect circular references which happen quite often. That is why python will occasionally run a
by codexon 11y ago
Reference counting is not a complete GC solution, it does not collect circular references which happen quite often.
That is why python will occasionally run a mark and sweep GC even though it says it uses reference counting.
- 1morethrowaway 11y agoIt's good enough by itself if you tell programmers not to create circular references and explicitly use weak references if they really need to. That opens you up to memory leaks from accidental circular references, of course, but again, it's a worthwhile tradeoff for many projects.
- codexon 11y agoWhen you have a scripting language with a GC you are targeting a class of users who can't or don't want to be careful enough to prevent circular references. Circular references aren't easy to avoid, sometimes there can be more than 3 levels of indirection. The mental overhead of preventing circular references is often times as high as manually managing memory yourself. If it was as good as you suggest, every new language would be using reference counting and not occasionally run mark and sweep.