SimpleRAII is a tiny garbage collection helper class that eases the use of the RAII idiom (Resource Acquisition Is Initialization).


When creating a new class, simply subclass the "SimpleRAII " class and encapsulate all "new ..." statements with "manage(new ...)". Do not use any delete statements!

Background & Example

In short the RAII idiom states that it's a good thing when dealing with resource allocation and deallocation in constructors and destructors. In the latter case, code that frees memory is always guaranteed to be executed, when the object is deleted from the stack. So, suppose you write a class MyClass that looks like this:

class MyClass {
MyClass(void) {
  s = new std::string();

~MyClass(void) {
  delete s;

  std::string * s;

The pointer variable s is initialized as a string objected on the heap which will deleted when the instance of MyClass runs out of scope. To safe yourself some writing whenever you want to do just that, you can use the SharedRAII helper class to achieve that same thing. MyClass would then look like this:

class MyClass : public SharedRAII {
  s = manage(new std::string());

  std::string * s;

Here, no destructor is needed anymore.

More information can be obtained from the Readme.txt in the download package at sourceforge.


jReflectServer 2.0
New version released | 1/4/2017

jReflectServer (formerly jReflect) has been updated. Version 2.0 allows distributed code ... Read More

Instantly backup your files on change | 3/21/2014

DocuCast is a real time file revision and backup system for use in professional and private ... Read More

jReflect: lightweight java web-server & -framework

jReflect is a very small & lightweight java web-server and -framework for ... Read More

More Blog Entries