I'm developing an app (iPad, Xcode 4.6, iOS 6.x) with a modal window and a UIProgressView updated on the main thread that shows two memory leaks once the task monitored by the UIProgressView is completed. If I remove the UIProgressView and thread calls from code, the leak does not appear. I've tried it with both a manually created UIProgressView and one in a StoryBoard. Program uses ARC.
The two leaks are WebCore/WebThreadCurrentContext [Malloc 16 bytes] and UIKit/GetContextStack [Malloc 64 bytes].
@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
Question 1: Do all the methods that are called from createImportFileInBackground: need to be wrapped in a @autoreleasepool{}. If so, does that include the methods in the other class that is sending the notifications back to this class?
Question 2: Am I missing something that is causing the leaks to occur?
Any help/suggestion would be appreciated. Thanks in advance! Tim