3 ms·
Thanks. I can see the pro in that choice. But the con would be memory starvation (assuming that heap is bounded as in the JVM). I think one middle-path could b
by hrjet 12y ago
Thanks. I can see the pro in that choice. But the con would be memory starvation (assuming that heap is bounded as in the JVM).
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
- kibwen 12y agoHeaps 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.