我正在內存分配上運行我的iOS應用程序分析器,並且檢測到當前已創建8MB內存,並且仍然存在於我的應用程序中。顯然有一些錯誤。所以,我鑽下來,這裏的形象,我可以告訴你:從儀器讀取內存分配結果
知道爲什麼這是什麼原因?這似乎是一個自動發佈的對象,所以不應該被釋放,而不是活在內存中?
以下是我正在調用該函數parseTagsInComment:
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSString *commentsText = [NSString stringWithFormat:@"%@ %@", self.imageComment_.username_, self.imageComment_.text_];
NSRange range;
range.location = 0;
range.length = commentsText.length;
NSMutableAttributedString* attrStr = [[NSMutableAttributedString alloc] initWithString:commentsText];
[attrStr setFont:[UIFont fontWithName:@"HelveticaNeue" size:14] range:range];
self.commentAttributedString_ = attrStr;
[attrStr release];
dispatch_async(dispatch_get_main_queue(), ^{
[weakSelf.commentsText_ setAlpha:0.0];
[weakSelf.commentsPostedTime_ setAlpha:0.0];
[weakSelf.commentsText_ setFrameWidth:weakSelf.contentView.frameWidth - weakSelf.profilePicture_.frameWidth - kCommentsPadding];
[weakSelf.commentsText_ setFrameHeight:weakSelf.imageComment_.commentHeight_ - 30];
[weakSelf.commentsText_ setAttributedString:weakSelf.commentAttributedString_];
[weakSelf.commentsText_ setLinkColor:weakSelf.textColor_];
NSString *timePosted = [NSString timestampToString:weakSelf.imageComment_.createdTime_];
CGSize commentsTimeSize = [timePosted sizeWithFont:weakSelf.commentsPostedTime_.font constrainedToSize:CGSizeMake(weakSelf.commentsText_.frameWidth, 50)];
[weakSelf.commentsPostedTime_ setText:timePosted];
[UIView animateWithDuration:0.3 animations:^{
[weakSelf.commentsText_ setAlpha:1.0];
[weakSelf.commentsPostedTime_ setAlpha:1.0];
} completion:^(BOOL finished){
[weakSelf parseTagsInComment];
}];
});
[pool release];
});
您確定這些百分比不代表每個代碼行所需的*時間量嗎? (即這是內存數據而不是分析數據)? – Turix 2012-07-24 05:26:12
@Turix我怎麼知道?我很確定它是內存..因爲我在Instruments上運行了分配測試而不是時間分析器 – adit 2012-07-24 05:26:36
是的,分配(或泄漏)應該是你想要的,你是對的。 (雖然我問我的問題的原因是因爲屏幕截圖中的百分比對我來說看起來似乎更合理)。順便說一句,這看起來不像我從xcode運行它時從Allocations或Profile獲得的輸出,所以很難說。 – Turix 2012-07-24 05:32:30