RAII vs gc (was fortran lib which provide python like data type)

Sturla Molden sturla.molden at gmail.com
Fri Jan 30 22:28:28 CET 2015

Rustom Mody <rustompmody at gmail.com> wrote:

> The case of RAII vs gc is hardly conclusive:
> http://stackoverflow.com/questions/228620/garbage-collection-in-c-why

The purpose of RAII is not to be an alternative to garbage collection
(which the those answers imply), but to ensure  deterministc execution of
setup and tear-down code. The Python equivalent of RAII is not garbage
collection but context managers.

Those answers is a testimony to how little the majority of C++ users
actually understand about the language.

A C++ statement with RAII like

   Foo bar(); 
   // suite

is not equivalent to

    bar = Foo()

in Python. It actually corresponds to

with Foo() as bar:


More information about the Python-list mailing list