IMP  2.0.1
The Integrative Modeling Platform
IMP::base::RefCounted Class Reference

Common base class for ref counted objects. More...

#include <IMP/base/RefCounted.h>

+ Inheritance diagram for IMP::base::RefCounted:

Detailed Description

This base class implements reference counting when used in conjunction with IMP::Pointer or IMP::WeakPointer objects. Objects which inherit from IMP::RefCounted should be passed using pointers and stored using IMP::Pointer and IMP::WeakPointer objects. Users must be careful to avoid cycles of reference counted pointers, otherwise memory will never be reclaimed.

Introduction to reference counting:
Reference counting is a technique for managing memory and automatically freeing memory (destroying objects) when it is no longer needed. In reference counting, each object has a reference count, which tracks how many different places are using the object. When this count goes to 0, the object is freed.

Python internally refence counts everything. C++, on the other hand, requires extra steps be taken to ensure that objects are reference counted properly.

In IMP, reference counting is done through the IMP::Pointer and IMP::RefCounted classes. The former should be used instead of a raw C++ pointer when storing a pointer to any object inheriting from IMP::RefCounted.

Any time one is using reference counting, one needs to be aware of cycles, since if, for example, object A contains an IMP::Pointer to object B and object B contains an IMP::Pointer to object A, their reference counts will never go to 0 even if both A and B are no longer used. To avoid this, use an IMP::WeakPointer in one of A or B.

IMP::RefCounted provides no public methods or constructors. It makes objects that inherit from it non-copyable.

See Also
IMP_REF_COUNTED_DESTRUCTOR()

Definition at line 72 of file base/RefCounted.h.


The documentation for this class was generated from the following file: