0

在我目前正在使用的应用程序中,我使用 Mailcore ( http://www.mronge.com/m/MailCore/API/ ) 来处理邮件服务器操作。我试图在后台通过 SMTP 连接发送消息。问题是,Leaks 告诉我,每次发送消息时都会发生相当多的内存泄漏。我试图弄清楚这是我的错还是 Mailcore 的错。这是代码:

从我的视图控制器:

-(void) send_rfq {

    CTCoreMessage *repMsg = [[[CTCoreMessage alloc] init] autorelease];
    NSDate *now = [NSDate date];

    NSString* msgString = [NSString stringWithFormat:@"Date#%@\nRFQ#%@\nSalesRep#%@",[now description], [rfq_entry get_uid],[rfq_entry get_repid]];
    [repMsg setBody:msgString];
    [repMsg setSubject:@"RFQ Assign"];

    [myAppDelegate performSelectorInBackground:@selector(send_msg:) withObject:repMsg];

    [self.navigationController popViewControllerAnimated:YES]; 
}

来自我的应用委托:

-(BOOL) send_bg:(CTCoreMessage*) msg {
    BOOL success = TRUE;
    @try {
        [CTSMTPConnection sendMessage:msg server:smtp_server username:smtp_uname password:smtp_pass port:smtp_port useTLS:smtp_tls useAuth:smtp_auth];
    }
    @catch (NSException * e) {
        //Msg failed to send;
        success = FALSE;
    }
    return success;
}

-(void) send_msg:(CTCoreMessage*) msg {
    NSAutoreleasePool *pool = [ [NSAutoreleasePool alloc] init];
    [msg setTo:[NSSet setWithObject:[CTCoreAddress addressWithName:@"testaccount" email:rfq_dest]]];
    [msg setFrom:[NSSet setWithObject:[CTCoreAddress addressWithName:@"RFQapp" email:rfq_src]]];
    if(![self send_bg:msg]) {
        UIAlertView * empty_alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Could not send." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
        [empty_alert show];
        [empty_alert autorelease];
    }
    [pool release];
}
4

1 回答 1

1

您发布的代码中没有泄漏。泄漏要么是误报,要么是代码中的其他地方。您是否尝试过使用 Instruments 分析您的应用程序?您是否尝试过使用 Build and Analyze 对代码进行静态分析?

于 2011-01-07T20:29:30.280 回答