Idrees Ashraf
Idrees Ashraf

Reputation: 1383

App crash due to memory leak

- (void)viewDidLoad {

    webCollectionOnScroller=[[NSMutableArray alloc] init];
    scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 370, 320, 94)];
    scroll.pagingEnabled = YES;
    currentWeb=0;
    globali=0;
    firstTime=0;
    [loadingWeb startAnimating];
    alertForLoading = [[UIAlertView alloc] initWithTitle:@"Loading..." message:@"link is being loaded.\n Please wait!" delegate:self cancelButtonTitle:@"Back" otherButtonTitles:nil];
    [alertForLoading show];
    UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];

    // Adjust the indicator so it is up a few pixels from the bottom of the alert
    indicator.center = CGPointMake(alertForLoading.bounds.size.width / 2, alertForLoading.bounds.size.height - 100);
    [indicator startAnimating];
    [alertForLoading addSubview:indicator];
    [NSThread detachNewThreadSelector:@selector(initializeParser)toTarget:self withObject:nil];
    [super viewDidLoad];
}

and this is the console error "-[linksGallery respondsToSelector:]: message sent to deallocated instance 0x639a890 [Switching to process 2211] "

It doesn't crash when I comment release statement on main view

-(IBAction) goToLinks{
    linksGallery *showLinks=[[linksGallery alloc] initWithNibName:@"linksGallery" bundle:nil];
    [self.navigationController pushViewController:showLinks animated:YES];
        //[showLinks release];
}

Upvotes: 0

Views: 296

Answers (4)

Mutawe
Mutawe

Reputation: 6524

Make your ViewDidLoad look like this :

- (void)viewDidLoad {

[super viewDidLoad];

webCollectionOnScroller=[[NSMutableArray alloc] init];
scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 370, 320, 94)];
scroll.pagingEnabled = YES;
currentWeb=0;
globali=0;
firstTime=0;
[loadingWeb startAnimating];
alertForLoading = [[UIAlertView alloc] initWithTitle:@"Loading..." message:@"link is being loaded.\n Please wait!" delegate:self cancelButtonTitle:@"Back" otherButtonTitles:nil];
[alertForLoading show];
UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];

// Adjust the indicator so it is up a few pixels from the bottom of the alert
indicator.center = CGPointMake(alertForLoading.bounds.size.width / 2, alertForLoading.bounds.size.height - 100);
[indicator startAnimating];
[alertForLoading addSubview:indicator];
[NSThread detachNewThreadSelector:@selector(initializeParser)toTarget:self withObject:nil];

}

Upvotes: 0

Mitul Nakum
Mitul Nakum

Reputation: 5564

Try out following codes

-(IBAction) goToLinks{
    linksGallery *showLinks=[[linksGallery alloc] initWithNibName:@"linksGallery" bundle:nil];
    [self.navigationController pushViewController:[showLinks mutableCopy] animated:YES];
    [showLinks release];
}

or

-(IBAction) goToLinks{
    linksGallery *showLinks=[[[linksGallery alloc] initWithNibName:@"linksGallery" bundle:nil] autorelease];
    [self.navigationController pushViewController:showLinks animated:YES];
    //[showLinks release];
}

Hope this will help

Upvotes: 0

Nishant B
Nishant B

Reputation: 2897

Try with putting the below line at first:

[super viewDidLoad];

inside the "dealloc()" function:

[super dealloc];

at the end of all releases.

Hope this will help you.

Upvotes: 1

Mark
Mark

Reputation: 6128

That error message means the instance of linksGallery has been released by the time you send it the message 'respondsToSelector'. To debug this try also setting it to null when you release it, then it won't crash, although it probably won't do what you want either.

Upvotes: 0

Related Questions