gpt4 book ai didi

iphone - 由于内存问题/MBProgressHUD 指示器导致应用程序崩溃

转载 作者:塔克拉玛干 更新时间:2023-11-02 10:15:12 24 4
gpt4 key购买 nike

我有一个奇怪的问题。我目前正在开发一个邮件应用程序,它曾经随机崩溃而没有错误或在我的控制台中记录。我检查了我的崩溃日志,它显示了低内存警告,并在我的应用程序旁边写了 jettisoned。 Crash Report

所以我怀疑这是一个内存问题,然后回去跟踪我的应用程序的内存使用情况。我使用分配工具来检测整体使用情况,当它的堆大小仅为 4.59 MB 时,我的应用程序崩溃了。 Instrument snapshot

工具指向我正在使用 MBProgressHUD 指标的函数。罪魁祸首是这一行:

[appDelegate showHUDActivityIndicatorOnView:self.parentViewController.view whileExecuting:@selector(refreshInBackground) onTarget:self withObject:nil withText:@"Loading"];

如果我将其替换为[self refreshInBackground] 一切正常,没有问题..

代码如下:

    -(void) showHUDActivityIndicatorOnView:(UIView*)view whileExecuting:(SEL)method 
onTarget:(id)target withObject:(id)object withText:(NSString*)label{
self.HUD = [[MBProgressHUD alloc] initWithView:view] ;
self.navigationController.navigationItem.hidesBackButton = YES;
[view addSubview:self.HUD];
self.HUD.delegate = nil;
self.HUD.labelText = label;
[self.HUD showWhileExecuting:method onTarget:target withObject:object animated:YES];
}

self.HUD 是一个被保留的属性。

稍作修改的showWhileExecuting方法如下:

- (void)showWhileExecuting:(SEL)method onTarget:(id)target withObject:(id)object animated:(BOOL)animated {

MyAppdelegate *appDelegate = (MyAppdelegate *)[UIApplication sharedApplication].delegate;
if(!appDelegate.isRequestActive)
{
methodForExecution = method;
targetForExecution = [target retain];
objectForExecution = [object retain];

// Launch execution in new thread
taskInProgress = YES;
[NSThread detachNewThreadSelector:@selector(launchExecution) toTarget:self withObject:nil];

// Show HUD view
[self show:animated];
}
else {
[self done];
}
}

目前我已经从我的应用程序中删除了它并且它现在工作正常并且即使使用 20 - 30 MB 堆内存也不会崩溃。

我不是在这里寻找具体的答案或解决方案。我正在寻找调试方法/调试问题的技术,以便我可以了解导致我的应用程序崩溃的原因。

是不是内存溢出了。如果是这样,那么我现在如何使用 20-30 MB。如果这不是内存问题,为什么我的崩溃报告程序会在我的应用程序名称旁边显示 jettisoned 。

罪魁祸首行 ([appDelegate showHUDActivityIndi​​catorOnView:self.parentViewController.view whileExecuting:@selector(refreshInBackground) onTarget:self withObject:nil withText:@"Loading"])

每次当我调用这个函数时,一些内存都会增加,因为一些元素被缓存了。但是当内存达到 4.5 MB 时......这条线导致它崩溃

如何找到此问题的根本原因。我如何弄清楚为什么 iOS 正在杀死我的应用程序,我的应用程序旁边写着被抛弃的原因

如有任何帮助或建议,我们将不胜感激。

最佳答案

好的。问题是我在我的 View 中添加了 HUD 进度条[view addSubview:self.HUD];

我忘记在它的委托(delegate)方法中将它从 super View 中移除:

- (void)hudWasHidden:(MBProgressHUD *)hud 
{
// Remove HUD from screen when the HUD was hidded
[HUD removeFromSuperview]; // app crashes at 4.59 MB if you comment this
[HUD release];
HUD = nil;
}

因为每次在一个 UIView 上添加几个 View ......我猜每个 UIView 顶部的 subview 数量有一个上限......苹果应该在他们的文档中提到这一点......

关于iphone - 由于内存问题/MBProgressHUD 指示器导致应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11068254/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com