Using malloc/free in Objective-C object
- by Itamar Katz
I have a class AudioManager with a member of type AudioBufferList *. (This is a struct declared in the CoreAudio framework). Since AudioBufferList is not a NSObject, I cannot retain it, so I have to alloc/free it (correct me if I'm wrong).
My question is, where is the 'right' place to free it? Currently I am doing it in the dealloc method of AudioManager. If I understand correctly, this method is invoked automatically once the release message is sent to the instance of AudioManager --- is that true? Is there any other recommended practice regarding using alloc/free on non-objects members of Objective-C objects?
Edit:
From Apples documentation:
Subclasses must implement their own
versions of dealloc to allow the
release of any additional memory
consumed by the object—such as
dynamically allocated storage for data
or object instance variables owned by
the deallocated object. After
performing the class-specific
deallocation, the subclass method
should incorporate superclass versions
of dealloc through a message to super:
Which makes things a little bit clearer - but more insights are appreciated.