3 ms·
Explain?
by reagency 11y ago
Explain?
- gavazzy 11y agoNot 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.
- shmerl 11y agoIt provides deterministic method of automated memory management and avoids this unpredictable latency issue.