此代碼的問題是,while循環執行時,內存使用量不斷增加。我想知道爲什麼這段代碼在while循環中不斷增加內存。 這裏的對象是吃內存。我該怎麼做才能讓內存不會在循環中增加。while循環內存問題
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSNumber *totalTime = [[self nowPlayingItem] valueForProperty:MPMediaItemPropertyPlaybackDuration];
while (self.currentPlaybackTime < [totalTime floatValue])
{
NSNumber *currentTime = [[NSNumber alloc] initWithFloat:self.currentPlaybackTime];
if([[NSThread currentThread] isCancelled])
{
[NSThread exit];
[newThread release];
}
else if([totalTime intValue] - [currentTime intValue] == 1.0)
{
if(currentTime)
[currentTime release];
break;
}
[currentTime release];
}
[pool release]
[池漏極];使用分配工具查找何時出現問題 – 0xDE4E15B 2011-04-07 06:46:33
正如我所提到的,while循環執行時內存會增加。還有什麼我可以從Allocations樂器中獲得的? – Dhawal 2011-04-07 06:54:05
如果你看到去年的WWDC視頻,你會發現他們把autorelease池放在了一邊。這會在每個週期釋放任何自動釋放對象,從而減少內存消耗。 – rckoenes 2011-04-07 07:22:57