对象从 NSMutableArray 更改为 NSData 再更改为 NSString

发布于 2024-09-26 05:02:36 字数 1036 浏览 0 评论 0原文

我有一个可以正常运行的程序。然后我从 http://github.com/matej/MBProgressHUD 下载了一些代码,以在做某事。

这是弹出进度表的代码。

[HUD showWhileExecuting:@selector(myTask) onTarget:self withObject:nil animated:YES];

myTask 方法运行时,这将显示一个进度表。

这是 showWhileExecuting 方法的代码。

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

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

如果我使用它来调用函数 myTask ,那么我的类属性之一将从 NSMutableString 更改为某处的 NSData 对象,然后再更改它将更改为 NSString。我在代码中没有看到任何导致这种变化的地方,所以这可能是某种错误。内存是否已损坏?是什么原因导致这种情况发生?

I have a program which works normally. Then I downloaded some code from http://github.com/matej/MBProgressHUD to show a progress meter when doing something.

This is the code that makes the progress meter pop up.

[HUD showWhileExecuting:@selector(myTask) onTarget:self withObject:nil animated:YES];

This will show a progress meter while the method myTask is running.

This is the code for the showWhileExecuting method.

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

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

If I use this to call the function myTask then one of my class properties will change from an NSMutableString to an NSData object somewhere, and then later on it will change to an NSString. I don't see anywhere in the code that causes this to change, so it's probably some kind of bug. Is memory getting corrupted? What's causing this to happen?

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

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

发布评论

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

评论(1

时间你老了 2024-10-03 05:02:36

最有可能的是内存(保留/释放问题)。如果你没有正确地固定一个物体,它可能会从你的身下释放出来。此时,操作系统将回收内存,操作系统可能会决定在那里存储其他内容。尝试打开 NSZombies,并仔细检查您的保留/释放/自动释放。

Most likely it's a memory (retain/release issue). If you don't properly retain an object, it may get released out from under you. At that point, the memory will be reclaimed by the OS, which may decide to store something else there. Try turning on NSZombies, and double checking your retain/release/autoreleases.

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