如何解决控制台未报告的故障

发布于 2024-10-20 02:05:17 字数 1391 浏览 4 评论 0原文

也许这是一个愚蠢的问题,但我有一个奇怪的问题。当我重新进入视图控制器时,每次尝试使用核心数据刷新数据库中的数据时,我的应用程序都会失败。如果我进入视图控制器并从互联网刷新数据,它就可以工作。但是,当我启动程序,输入视图控制器,然后弹出它并重新输入并尝试刷新数据时,它失败并且视图控制器中没有记录任何内容。我不知道为什么会这样。所以我尝试调试它,但问题消失了。当我在没有调试模式的情况下再次尝试后,它再次失败。我不知道为什么。会不会是分配的问题,或者是没有释放的问题?这是我的 -viewDidLoad 实现:

- (void)viewDidLoad {
    pool = [[NSAutoreleasePool alloc] init];

    if (managedObjectContext_ == nil) 
    { 
        managedObjectContext_ = [[(NavTestAppDelegate *)[[UIApplication sharedApplication] delegate] managedObjectContext] autorelease]; 
    }

    UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(insertNewObject)];
    self.navigationItem.rightBarButtonItem = addButton;
    [addButton release];

    prikazDatabaseArray = [[[NSMutableArray alloc] init]retain];

    NSDate *now = [NSDate date];
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"dd.MM.yyyy"];
    datumOd = [[dateFormatter stringFromDate:now] retain];

    [dateFormatter release];

    VObrat = YES;
}    

使用

NSAutoreleasePool *pool;
NSURLConnection *theConnection;
NSMutableURLRequest *theRequest;
NSData *xmlData;
NSData *xmlFile;
NSXMLParser *addressParser;

我也在我的代码中 。如果可以的话,至少帮我找到问题所在,因为没有调试和控制台,我感觉像个盲人。

多谢

Maybe it is silly question, but I have an curious problem. My app fails every time I try to refresh my data in database using core data when I re-enter the view controller. If I enter the view controller and refresh data from internet it works. However, when I start the program, enter the view controller, then pop it and re-enter and try refresh data, it fails and nothing is logged in view controller. I do not know why it happens. So I tried to debug it but the problem disappeared. After I tried again without debug mode it failed once more. I do not know why. Could it be problem of allocation, or something not released? Here's my implementation of -viewDidLoad:

- (void)viewDidLoad {
    pool = [[NSAutoreleasePool alloc] init];

    if (managedObjectContext_ == nil) 
    { 
        managedObjectContext_ = [[(NavTestAppDelegate *)[[UIApplication sharedApplication] delegate] managedObjectContext] autorelease]; 
    }

    UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(insertNewObject)];
    self.navigationItem.rightBarButtonItem = addButton;
    [addButton release];

    prikazDatabaseArray = [[[NSMutableArray alloc] init]retain];

    NSDate *now = [NSDate date];
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"dd.MM.yyyy"];
    datumOd = [[dateFormatter stringFromDate:now] retain];

    [dateFormatter release];

    VObrat = YES;
}    

I also use

NSAutoreleasePool *pool;
NSURLConnection *theConnection;
NSMutableURLRequest *theRequest;
NSData *xmlData;
NSData *xmlFile;
NSXMLParser *addressParser;

in my code. If you could, at least help me find where I have the problem, because without debug and console I feel like a blind man.

Thanks a lot

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

戏舞 2024-10-27 02:05:17

从行 managedObjectContext_ = [[(NavTestAppDelegate *)[[UIApplication sharedApplication] delegate] ManagedObjectContext] autorelease]; 中删除 autorelease

您没有保留,因此您不应该(自动)释放它。


编辑:我明白了,还有更多。

删除 prikazDatabaseArray = [[[NSMutableArray alloc] init]retain]; 中的保留。 Alloc 已经保留了你的对象。不需要做两次。

并在方法结束时删除自动释放池或将其耗尽。

您应该考虑阅读内存管理编程指南

remove the autorelease from the line managedObjectContext_ = [[(NavTestAppDelegate *)[[UIApplication sharedApplication] delegate] managedObjectContext] autorelease];

You didn't retain, so you should not (auto)release it.


Edit: I see, there's more.

remove the retain in prikazDatabaseArray = [[[NSMutableArray alloc] init]retain];. Alloc retains your object already. No need to do it twice.

And get rid of the autoreleasepool or drain it at the end of the method.

You should consider to read the Memory Management Programming Guide again.

治碍 2024-10-27 02:05:17

如果您要创建自己的池,那么您需要在相同的上下文或方法或循环中释放该池。

你应该使用[池排水]。

如果您无法看到使用性能工具运行的崩溃日志,它将为您提供错误的位置。

if you are creating your own pool then you need to release the pool in the same context or method or loop.

you should use [pool drain] for that.

if you are not able to see your crash log you run with performance tool it will give you the location where u are doing wrong.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文