RFC: Proposal: Deterministic Object Destruction
ooomzay at gmail.com
ooomzay at gmail.com
Sat Mar 3 18:05:10 EST 2018
On Saturday, March 3, 2018 at 4:33:59 PM UTC, Michael Torrie wrote:
> On 03/03/2018 09:02 AM, ooomzay wrote:
> > I can assure you that RAII does what it says on the tin and is relied on in
> > many critical systems to release resources robustly ... given the
> > pre-requisite deterministic destruction.
>
> Sure but did you read what Paul Moore wrote?
Yes.
> He said RAII works in C++
> because objects are allocated on the *stack* with strict lifetimes and
> scopes.
Well he was not telling you the whole story: RAII works just as well with heap objects using smart pointers (unique_ptr and friends) which are a closer analogy to python object references.
> In C++, Heap-allocated objects must still be managed manually, without
> the benefit of RAII,
No one should be manually managing resources on the heap in C++. They should be using smart pointers.
> for much of the same reasons as people are giving
> here for why RAII is not a good fit for Python.
...for much the same reasons I am giving here for why RAII could
be a very good fit for python.
> There are smart pointer
> objects that try to give RAII semantics to heap-allocated objects, with
> varying degrees of success. In other words there are some limitations.
Not sure what limitations you are evoking here but I have not had to write a delete or suffered a resource leak in C++ for many years. (we rolled our own smart pointers before they were standardised).
> Python does not have stack-allocated objects, so the same issues that
> prevent RAII from automatically applying in C++ to heap objects exist here.
False premise, false conclusion.
More information about the Python-list
mailing list