views:

58

answers:

1

I have a memory leak in this code. I am busting it since 2 weeks and I am starting to be mad. Thanks in advance for your help :)

+(void) makeEvent:(int) event:(AppleEvent *)theEvent
{
    int sig = 'dock';
    OSErr err;
    AEAddressDesc targetDesc;

    targetDesc.descriptorType = typeNull;
    targetDesc.dataHandle = nil;

    err = AECreateDesc(
                   typeApplSignature,
                   &sig, sizeof(int),
                   &targetDesc
                   );
    if(err) { NSLog(@"Error creating descriptor: %i\n", err); }

    err = AECreateAppleEvent(
                         'DKoP', event,
                         &targetDesc,
                         kAutoGenerateReturnID, kAnyTransactionID,
                         theEvent
                         );
    if(err) { NSLog(@"Error creating event: %i\n", err); }

    AEDisposeDesc(&targetDesc);
    targetDesc.descriptorType = typeNull;
    targetDesc.dataHandle = nil;
}

addIntParm message:

+(void) addIntParm:(int) parm: (int) keyword: (AppleEvent *)theEvent
{
    OSErr err = AEPutParamPtr(
                              theEvent, keyword,
                              typeSInt32, &parm, sizeof(parm)
                              );
    if(err) { NSLog(@"Error setting parameter: %i\n", err); }
}

addFloatParm message:

+(void) addFloatParm:(float) parm: (int) keyword: (AppleEvent *)theEvent
{
    OSErr err = AEPutParamPtr(
                              theEvent, keyword,
                              typeIEEE32BitFloatingPoint, &parm, sizeof(parm)
                              );
    if(err) { NSLog(@"Error setting parameter: %i\n", err); }
}

sendEvent message:

+(void) sendEvent:(AppleEvent *)theEvent
{
    OSErr err = AESend(
                       theEvent, nil, kAENoReply, //kAEWaitReply
                       kAENormalPriority, kNoTimeOut,
                       nil, nil
                       );
    if(err) { NSLog(@"Error sending: %i\n", err); }
}

Test message:

+ (void) Test:(int)wid:(int)w:(int)h:(void*)points
{
    AppleEvent theEvent;
    [self makeEvent:'warp' :&theEvent];
    [self addIntParm:wid :'wnid' :&theEvent];
    [self addIntParm:w :'wwrp' :&theEvent];
    [self addIntParm:h :'hwrp' :&theEvent];
    [self addDataParm:points :sizeof(float)*4*h*w :'pots' :&theEvent];
    [self sendEvent:&theEvent];
    AEDisposeDesc(&theEvent);
}
+1  A: 
Dave DeLong
Thanks for your help, Actually I dispose it (last line of Test function)
AP