PrimoBurner(tm) for C++
4.6
CD, DVD and Blu-ray Software Development Kit
|
Memory management is fundamental to using PrimoBurner effectively and efficiently. This topic is essential reading for all developers who use PrimoBurner. For managing memory PrimoBurner uses a reference-counting mechanism, and a policy of object ownership that is suggested by the names of interfaces and methods.
Ownership Policy
When trying to understand memory management in a PrimoBurner application, it is helpful to think not in terms of memory management per se, but instead in terms of object ownership. An object may have one or more owners; it records the number of owners it has using a reference count. If an object has no owners (if its reference count drops to zero), it is disposed of (freed). PrimoBurner defines the following rules for object ownership and disposal.
There are two distinct types of objects in PrimoBurner:
These objects keep an internal reference count which is controlled via the primo::Reference interface. The count is increased via Reference::retain and decreased via Reference::release. By convention when an object with a reference count of 1 is released it is destroyed. As part of the destruction process the object releases all other objects that it has retained itself.
A PrimoBurner object is created through one of the following verbs: create, clone, copy and read.
An object that is created by one of the methods described above is reference counted. Its initial reference count is 1. The user code is responsible for managing such an object and it should be released when it is not needed anymore.
When an object is passed as a parameter to a PrimoBurner function it may or may not be retained by the function. This depends on how the parameter is used in the Library and this is stated clearly in the documentation. The basic principle is that when the object will be used by PrimoBurner after the function returns then it is retained by the Library (for example when a CDTrack object is passed to CDTrackList::add it is retained since it becomes part of the list). If the passed object is used only within the function then it is not retained (for example when a AudioOutput object is passed to AudioCD::readTrackFromCD it is not retained because it is used only within this method).
A reference counted object can be returned either as a result of a creating (clone/copy/read) operation (see Creating Objects above) or because the object already exists and it is being accessed. As already mentioned when a new object is created the user code is responsible to release it when it's not needed anymore. But when a reference counted object is simply accessed the user code should not release it. It should do so only if it has previously retained the object. This is an option that can be used when the returned object must be detached from the container (for example the client code may want to keep a CDTrack object returned by CDTrackList::at even when the CDTrackList that holds it is destroyed).
The objects that fall in this category cannot be created separately by the user code. They exist only in the context of another PrimoBurner object and cannot be detached from it. Their lifetime depends only on the object that holds them. Objects without reference management do not inherit from primo::Reference.
Examples of such objects are:
AudioInputList returned by AudioCD::audioInputs,
UdfVolumeProps returned by DataDisc::udfVolumeProps,
BootProps returned by DataDisc::bootProps, etc.