我正在開發一個應用程序(iPad,Xcode 4.6,iOS 6.x),並在主線程上更新了UIProgressView,該任務顯示兩次內存泄漏UIProgressView已完成。如果我從代碼中刪除UIProgressView和線程調用,則不會顯示泄漏。我用手動創建的UIProgressView和StoryBoard中的一個嘗試了它。程序使用ARC。UIProgressView泄漏(WebThreadCurrentContext和GetContextStack)
這兩個泄漏是WebCore/WebThreadCurrentContext [Malloc 16字節]和UIKit/GetContextStack [Malloc 64字節]。
@interface KICreateImportFileViewController()
...
@property (strong, nonatomic) UIProgressView *convertedRecordsProgressView;
@end
@implementation KICreateImportFileViewController
- (void)viewDidLoad
{
[super viewDidLoad];
...
// config the UIProgressView
CGRect pFrame = CGRectMake(20, 100, 500, 9);
self.convertedRecordsProgressView = [[UIProgressView alloc] initWithFrame:pFrame];
self.convertedRecordsProgressView.progressViewStyle = UIProgressViewStyleDefault;
[self.view addSubview:self.convertedRecordsProgressView];
}
- (void)viewDidAppear:(BOOL)animated
{
// listen for a NSNotification with info regarding process from class KITestParser
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(updateProgressViewWhenNotified:)
name:@"KITestParser:Progress Updated"
object:self.originalFile.testParser];
// Begin the background process that will update the UIProgressView
[self performSelectorInBackground:@selector(createImportFileInBackground:) withObject:nil];
}
- (void)viewWillDisappear:(BOOL)animated
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
[super viewWillDisappear:animated];
}
#pragma mark - Notifications
-(void)updateProgressViewWhenNotified:(NSNotification *)notification
{
NSNumber* progress = (NSNumber *)[notification.userInfo valueForKey:@"progressRatio"];
[self updateProgressViewOnMainThread:progress];
}
#pragma mark - Private class methods
- (void)createImportFileInBackground:(id)obj
{
// Background processes aren't automatically protected by ARC unless you wrap the function in the auto-release pool.
@autoreleasepool {
[self.originalFile createImportFile];
}
}
- (void)updateProgressViewOnMainThread:(NSNumber *)progress
{
[self performSelectorOnMainThread:@selector(updateProgressView:) withObject:progress waitUntilDone:NO];
}
- (void)updateProgressView:(NSNumber *)progress
{
[self.convertedRecordsProgressView setProgress:[progress floatValue] animated:YES];
}
@end
問題1:盡一切從createImportFileInBackground調用的方法:需要被包裹在一個@autoreleasepool {}。如果是這樣,是否包含其他類中的方法將通知發送回此類?
問題2:我是否錯過導致泄漏發生的事情?
任何幫助/建議,將不勝感激。提前致謝! Tim
但是,我看到大約15分鐘後(我假設這是游泳池正在清理東西的時候),應用程序退出,這是我沒有采取其他行動(讓應用程序閒置)。無論我是否使用樂器,都會發生崩潰。如果它仍然存在,我會提交一個錯誤。 – 2013-03-02 01:42:24