IMP::RefCounted Class Reference
Detailed Description
Common base class for ref counted objects.
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()
The documentation for this class was generated from the following files: