应用程序因内存泄漏而崩溃

时间:2012-05-23 11:52:53

标签: iphone ios

- (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];
}

这是控制台错误“ - [linksGallery respondsToSelector:]:发送到解除分配的实例0x639a890的消息 [切换到流程2211] “

当我在主视图上评论发布声明时,它不会崩溃

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

4 个答案:

答案 0 :(得分:1)

首先尝试使用以下行:

[super viewDidLoad];

在“dealloc()”函数中:

[super dealloc];

在所有版本的最后。

希望这会对你有所帮助。

答案 1 :(得分:0)

该错误消息表示您在发送消息时已释放linksGallery的实例' respondsToSelector'。要调试这个,尝试在释放它时将其设置为null,然后它不会崩溃,尽管它可能不会做你想要的。

答案 2 :(得分:0)

尝试以下代码

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

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

希望这会有所帮助

答案 3 :(得分:0)

使您的ViewDidLoad看起来像这样:

- (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];

}