0

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

Tim Newton
  • 1,463
  • 1
  • 13
  • 13

1 Answers1

0

Simple answer: You are using ARC, don't worry about it.

Elaborated: I've seen this with every ARC project I've ever had. The leaks tool will identify leaks in framework code. Are they truly leaks? Is the tool giving false positives? Answer: Who cares. Even if you knew if they were a real leak or not, the best solution you could have would be to file a bug with apple. You have no recourse, no action you can take. Forget about it.

HackyStack
  • 4,887
  • 3
  • 22
  • 28
  • Thanks, however, I'm seeing that after about 15 minutes (I'm assuming that's when the pool is cleaning things up), the app quits, that is with no other action on my part (letting the app be idle). The crash happens whether I use Instruments or not. If it persists, I'll submit a bug. – Tim Newton Mar 02 '13 at 01:42