Search code examples
c++memoryprogramming-languagesraii

Is there a language with RAII + Ref counting that does not have unsafe pointer arithmetric?


RAII = Resource Acquisition is Initialization

Ref Counting = "poor man's GC"

Together, they are quite powerful (like a ref-counted 3D object holding a VBO, which it throws frees when it's destructor is called).

Now, question is -- does RAII exist in any langauge besides C++? In particular, a language that does not allow pointer arithmetric / buffer overflows?


Solution

  • Perl 5 has ref counting and destructors that are guaranteed to be called when all references fall out of scope, so RAII is available in the language, although most Perl programmers don't use the term.

    And Perl 5 does not expose raw pointers to Perl code.

    Perl 6, however, has a real garbage collector, and in fact allows the garbage collector to be switched out; so you can't rely on things being collected in any particular order.

    I believe Python and Lua use reference counting.