4 ms·
How would the language guarantee no use-after-free scenarios? let x = new Foo() if (y == 1) { recycle x } println(x)
by bjourne 2y ago
How would the language guarantee no use-after-free scenarios?
let x = new Foo()
if (y == 1) {
recycle x
}
println(x)
- flohofwoe 2y agoI guess that's what the 'copy count' is for. After 'recycle x', the copy-count for the reference 'x' would be 0, so it's invalid to use. That would be trivial to do as a runtime check, don't know if the compiler is smart enough to catch such things at compile time. Also not sure if the idea of a 'copy count' is better than a 'generation counter' which also provides runtime protection against dangling access, e.g. see https://floooh.github.io/2018/06/17/handles-vs-pointers.html https://floooh.github.io/2018/06/17/handles-vs-pointers.html