Re:Rust means never having to close a socket
by kibwen on Wednesday October 08, 2014 @10:18AM
(#8426967)
Heaps aren't bounded in systems contexts; a process is free to gobble up the entire address space if left unchecked, which would (hopefully) result in your process being killed by the OS.
I believe we have discussed your first bullet point there, with regard to attempting to free waiting-for-the-scope-to-end-but-not-being-used memory in the event that allocation fails. But this is a hairy subject, and is beyond my expertise.
Note that your third bullet point does cause memory to be freed immediately, because the `drop` function is a scope all its own.
I think one middle-path could be to mark the resource as released as soon as compiler detects it, and then release it
1. when the allocator is starved or
2. when the resource goes out of scope
3. when drop() is explicitly called