Re: Deterministic destruction and RAII idioms in Python



Hi Paul,

> I didn't understand then. I thought by "deterministic destruction"
> you meant relying on what CPython does now, which is reference
> counting with destruction when the last reference is released.

I effectively do mean that. In C++ it is guaranteed that a destructor
will be called on an object when it goes out of scope, no matter how
that happens (normal exit, exception, etc...). C++-style RAII just
refers to wrapping up resources in classes so that you don't need to
worry about explicitly freeing them.

> I do remember thinking C++ RAII
> was a nuisance because you had to create classes with destructors to
> do what other languages did with try/finally or the equivalent.

It really depends how often you have to deal with getting/releasing
resouces. You can define a class once and then just deal the resource
in your code with a single line (creating the object). It can also
simplify things when you are dealing with the simultaneous management
of multiple resources. In any case, this is now getting off topic.

Thanks for your input! It was fun.

.



Relevant Pages

  • Re: A re-announce on GCs defects
    ... B> Reason 1: ... B> There is delay between the wanted destruction and the actual ... B> The need for weak reference makes the destruction delay logically ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Ion #12 - That Was a Story?
    ... It seems a clear reference to Hal Jordan being unable to accept the ... destruction of Coast City. ... as Kyle couldn't let his mom go and tried to bring her back...he just ...
    (rec.arts.comics.dc.universe)
  • Re: Lock-free reference counting
    ... OCaml is most likely using compiler support and explicit destruction. ... run the following code as many times as you like and reference counting ... to a temporary objectr, the standard guranteeing that the temporary ...
    (comp.programming)
  • Re: Destructors and exceptions
    ... > left to the garbage collector and you have no influence on it. ... collected using reference counting. ... of view is that the exception mechanism doesn't unwind scope. ... the destruction of locals in the presence of an exception ...
    (comp.lang.python)