Disposing of Apple Event Data Structures
Disposing of Apple Event Data Structures
Whenever you use Apple Event Manager functions to create a
descriptor record, descriptor list, or Apple event record, the
Apple Event Manager allocates memory for these data structures.
Likewise, when you extract a descriptor record by using
Apple Event Manager functions, the Apple Event Manager creates a
copy of the descriptor record for you to use.
Whenever you are done using a descriptor record or descriptor list that you
have created or extracted from an Apple event, you must dispose of the
descriptor record-and thereby deallocate the memory it uses-by calling the
AEDisposeDesc function.
Also, when you are done using the Apple event specified in the AESend
function and finished with the reply Apple event, you should dispose of their
descriptor records using the AEDisposeDesc function. You should dispose of
them even if AESend returns a nonzero result code.
Once you are done using them, you should dispose of any Apple event data
structures created or returned by these functions:
Even if you add a descriptor record to an Apple event (for example, when you
create a descriptor record by calling AECreateDesc and then put a copy of it
into a parameter of an Apple event by calling AEPutParamDesc), you're
still responsible for disposing
of the original descriptor record.
In one case, the Apple Event Manager does take care of disposing of the
Apple event data structures for you: when your handler returns to
AEProcessAppleEvent, the Apple Event Manager disposes of the Apple
event and the reply Apple event. Note that your handler is still responsible for
disposing of any Apple event data structures created when extracting data from
the Apple event. The Apple event and reply Apple event that your handler
receives are only copies of the originals. The client application is responsible
for disposing of the original data structures.