【问题标题】:Memory Management Issue with copy in connectionDidFinishLoadingconnectionDidFinishLoading 中复制的内存管理问题
【发布时间】:2012-10-24 07:15:41
【问题描述】:

我通过这个委托方法将 connectionDidFinishLoading 中的 _resultArray 对象从一个类传递到另一个类。我在 dealloc 中释放,但我不确定它是否可以。如何释放这个 _resultArray..

这是我的代码..

-(void)connectionDidFinishLoading:(NSURLConnection *)connection{
    NSString *urlDataString = [[NSString alloc]initWithData:receiveData 
        encoding:NSUTF8StringEncoding];
    NSMutableDictionary *soapDictionary = nil;
    soapDictionary = [parser objectWithString:urlDataString error:&error];
    resultArray = [soapDictionary copy];
    [urlDataString release];
    [self soapResultSurvey:resultArray];
}

//Delegate Method
-(void)soapResultSurvey:(id)_resultSurvey{
    [delegate soapResultSurvey:_resultSurvey];
}

【问题讨论】:

  • 这取决于你在委托方法“soapResultSurvey 中做什么。你能告诉我们委托代码方法吗?
  • 您使用副本有什么特别的原因吗?

标签: iphone memory-management


【解决方案1】:
resultArray = [[soapDictionary copy] autorelease];

然后记住 resultArray 将在线程结束时被释放,所以如果你的委托需要保留它,那么,在你的委托soapResultSurvey:方法中做它

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-10-28
    • 2018-03-31
    • 2017-08-02
    • 1970-01-01
    相关资源
    最近更新 更多