[futurebasic] AECreateAppleEvent memory leak

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : March 1999 : Group Archive : Group : All Groups

From: "Steven J. Stratford" <sstrat@...>
Date: Sat, 20 Mar 1999 19:07:16 -0600
This works, but it leaks 32 bytes of memory on each call:

LONG IF FN AECreateDesc(_typeApplSignature,mondoSig&,4,myAEDesc) = _noErr
  LONG IF FN
AECreateAppleEvent(_kMondoEventClass,_kMondoEventID,myAEDesc,_kAutoGenerateRetur
nID,_kAnyTransactionID,myAEvent) = _noErr
......snip putting parameters, sending the event, and retrieving the reply
  OSErr& = FN CheckError(FN AEDISPOSEDESC(#@myAEvent))
ENDIF
OSErr& = FN CheckError(FN AEDISPOSEDESC(#@myAEDesc))
ENDIF

myAEDesc and myAEvent are defined the way they're supposed to be:

 DIM myAEvent.appleEvent                          'A new Apple Event
 DIM myAEDesc.AEDesc                              'Descriptor record for
Apple Event

mondoSig& = _"@CME"                              'for sending email to
MondoMail Pro on my server

If I watch MEM(_freemem) carefully before and after each line (by using a
little ALERT), all of the memory is not recovered on the second
AEDISPOSEDESC call. 32 bytes are lost. From experience, it sounds like a
handle or two was not disposed of properly, but  I can't figure where, even
with the Apple "Creating and Sending AppleEvents" documentation and the
nice series on Appleevents in Inside Basic.

If I leave out creating and disposing of the appleevent, no memory is lost,
so it has something to do with creating and disposing the appleevent. But
all the errors are coming back _noErr. Can someone with some experience
with appleevents help me out here? Thanks. CC me if you send a reply
because I'm on digest.

Here's the appleevent and AEDesc structures I'm using:

DIM RECORD AEDesc
 DIM descType&
 DIM descHandle&
DIM END RECORD _AEDesc

DIM RECORD AEKeyDesc
 DIM descKey&
 DIM descContent.AEDesc
DIM END RECORD _AEKeyDesc

DIM RECORD AEAddressDesc
 DIM addressDesc.AEDesc
DIM END RECORD _AEAddressDesc

DIM RECORD AEDescList
 DIM descList.AEDesc
DIM END RECORD _AEDescList

DIM RECORD AERecord
 DIM recordDesList.AEDescList
DIM END RECORD _AERecord

DIM RECORD AppleEvent
 DIM AEEventRecord.AERecord
DIM END RECORD _AppleEvent

Here's the two assembly language routines:

LOCAL MODE
LOCAL FN AECreateDesc(typeCode&,@dataPtr&,dataSize&,@result&)
 `     subq.l  #2,sp
 `     move.l  ^typeCode&,-(sp)
 `     move.l  ^dataPtr&,-(sp)
 `     move.l  ^dataSize&,-(sp)
 `     move.l  ^result&,-(sp)
 `     dc.w    $303C,$0825,$A816
 `     move.w  (sp)+,D0
 `     ext.l   D0
END FN

LOCAL MODE
LOCAL FN
AECreateAppleEvent(theAEEventClass&,theAEEventID&,@target&,returnID%,transaction
ID&,@result&)
 `     subq.l  #2,sp
 `     move.l  ^theAEEventClass&,-(sp)
 `     move.l  ^theAEEventID&,-(sp)
 `     move.l  ^target&,-(sp)
 `     move.w  ^returnID%,-(sp)
 `     move.l  ^transactionID&,-(sp)
 `     move.l  ^result&,-(sp)
 `     dc.w    $303C,$0B14,$A816
 `     move.w  (sp)+,D0
 `     ext.l   D0
END FN

--Steve