3 ms·
Not OP, but RAII provides deterministic destruction. That is, it is provable exactly when the object will be deleted. From wikipedia: "Object destruction varie
by gavazzy 11y ago
Not OP, but RAII provides deterministic destruction. That is, it is provable exactly when the object will be deleted.
From wikipedia: "Object destruction varies, however – in some languages, notably C++, automatic and dynamic objects are destroyed at deterministic times, such as scope exit, explicit destruction (via manual memory management), or reference count reaching zero; while in other languages, such as C#, Java, and Python, these objects are destroyed at non-deterministic times, depending on the garbage collector, and object resurrection may occur during destruction, extending the lifetime."
https://en.wikipedia.org/wiki/Object_lifetime#Determinism https://en.wikipedia.org/wiki/Object_lifetime#Determinism
- pjmlp 11y agoYou can have RAII in C#, Java and Python by making use of using/try-with-resources/with, or HOF with monadic constructs. Yes, it isn't as easy as declaring a templated handle manager class on the stack (it won't work for heap objects) in C++, but it also gets the job done.