2010-07-02 75 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