If you create a descriptor, you must dispose of it when you are finished with it to prevent memory leaks. For example, when you extract a descriptor using the AEGetParamDesc, AEGetAttributeDesc, AEGetNthDesc, or AEGetKeyDesc function, you get a copy of the descriptor. You call the AEDisposeDesc function to dispose of your copy, thereby deallocating the memory used by its data.
Listing 4-6 shows how to dispose of a descriptor list returned by AEGetParamDesc.
Listing 4-6 Disposing of a descriptor list obtained from the direct object of an Apple event
AEDescList docList; |
OSErr err; |
err = AEGetParamDesc(theAppleEvent, keyDirectObject, typeAEList, &docList); |
// Check for error, then perform operations on the descriptor list here. |
AEDisposeDesc(&docList); |
You can safely call AEDisposeDesc on a null descriptor (but not on a null pointer!) A null descriptor is one that has been initialized as shown in the following code snippet.
AEDesc someDesc = { typeNull, 0L }; |
// Code to obtain a descriptor, which may fail. |
// Safe to dispose, whether or not previous code succeeded. |
AEDisposeDesc(&someDesc); |
You can perform the same initialization using the AEInitializeDesc function, as shown in this code snippet.
AEDesc someDesc; |
AEInitializeDesc(&someDesc); |
When you obtain a copy of a descriptor with one of the buffer-based functions, such as AEGetAttributePtr or AEGetNthPtr, the data is copied into a buffer provided by your application. You must then free any allocated memory when finished with the buffer.
Last updated: 2007-10-31