2010-07-02 110 views
0

我得到的内存泄漏在我的对象设置可以任何一个帮助我解决这个??对象内存泄漏

代码:

- (void)setEstimateTax2Type:(NSString *)aEstimateTax2Type 
{ 

if ((!estimateTax2Type && !aEstimateTax2Type) || (estimateTax2Type && aEstimateTax2Type && [estimateTax2Type isEqualToString:aEstimateTax2Type])) return; 

[estimateTax2Type release]; 
estimateTax2Type = [aEstimateTax2Type copy] ; 
} 

感谢的提前。

Monish。

回答

0

您的条件:

if (
    (!estimateTax2Type && !aEstimateTax2Type) || 
    (estimateTax2Type && aEstimateTax2Type && 
    [estimateTax2Type isEqualToString:aEstimateTax2Type]) 
) return; 

出现释放内存之前终止功能:

[estimateTax2Type release]; 

虽然我没有看到任何alloc

+0

仅当两个对象都为零或相等时条件终止方法。所以它应该是可以的。 – JeremyP 2010-07-02 08:48:21

2

得到二传手的最简单方法正确(例如,您的情况完全没有必要):

//.h 
@property (nonatomic, copy) NSString *estimateTax2Type; 
//.m 
@synthesize estimateTax2Type; 
+0

请注意,有了这个,你仍然需要实现dealloc并发布估计值.Tax2Type – cobbal 2010-07-02 08:55:16

1

向nil发送消息没有问题。所以你的测试可以是:

if ([aEstimateTax2Type isEqualToString: estimateTax2Type]) 
{ 
    return; 
} 

但是,这不是你的泄漏的原因。我怀疑,你没有在你的dealloc方法中发布estimateTax2Type。

1

你有没有dealloc方法释放estimateTax2Type当你是一个类是dealloced?

- (void)dealloc { 
    [estimateTax2Type release]; 
    [super dealloc]; 
} 
+0

感谢所有的宝贵建议。 – monish 2010-07-02 08:58:44