If an object was create in function main and the program exit is also in function main, then the object never will be released (only when program exits). It means it is possible to allocate something, to write a destructor for it, but because of an exception, the point, where the destructor is called, will be missed (may be even a thread will be killed, but program doesn't exit, main's stack is present and all it's referenced objects are alive).Rusky wrote:Because all heap objects have an owner somewhere on the stack (directly or indirectly)
Also, it can be said, that every object has an owner somewhere in the heap. But no automatic memory management system can determine if an object is still in use or not if a developer just forget to set the object's reference to null.
Generally speaking, the detection of a situation, when an object should be released, is not as simple as Rust designers think (only stack based deallocation is not enough).