Apple Developer Connection
Member Login Log In | Not a Member? Contact ADC

< Previous PageNext Page > Hide TOC

Disposing of Apple Event Data Structures

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.



< Previous PageNext Page > Hide TOC


Last updated: 2007-10-31




Did this document help you?
Yes: Tell us what works for you.

It’s good, but: Report typos, inaccuracies, and so forth.

It wasn’t helpful: Tell us what would have helped.
Get information on Apple products.
Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Copyright © 2007 Apple Inc.
All rights reserved. | Terms of use | Privacy Notice