4 ms·
> * Lifetimes completely confuse me, as it seems like they would be handled by garbage collection? Interesting misconception :) Lifetime is used to avoid garb
by xiaq 12y ago
> * Lifetimes completely confuse me, as it seems like they would be handled by garbage collection?
Interesting misconception :)
Lifetime is used to avoid garbage collection. By expressing the lifetime of a variable preciously in the code, the compiler knows statically (i.e. when compiling instead of in runtime) when an object can be destroyed, avoiding GC overhead and offering deterministic destructure.