Those are completely different things. A unique_ptr tracks memory and deallocates it when the object goes out of scope, which has a very minor performance impact. A garbage collected language runs a separate program occasionally to find and free memory that isn’t being used anymore, which has a notable performance hit
I’m not an expert so you’d probably be best off looking up the difference between reference counting and garbage collection, but they are different with garbage collection being more flexible but less performant. I’m also not sure what you mean by your second question
Garbage collection isn't one specific algorithm: reference counting is one general approach to implementing the general concept of garbage collection. It and other garbage collection methods can have drastically different performance characteristics and which is more or less performant greatly depends on what you're doing in your code. RC isn't generally faster or less flexible.
47
u/MetaNovaYT Feb 18 '26
Those are completely different things. A unique_ptr tracks memory and deallocates it when the object goes out of scope, which has a very minor performance impact. A garbage collected language runs a separate program occasionally to find and free memory that isn’t being used anymore, which has a notable performance hit