对象从 NSMutableArray 更改为 NSData 再更改为 NSString
我有一个可以正常运行的程序。然后我从 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最有可能的是内存(保留/释放问题)。如果你没有正确地固定一个物体,它可能会从你的身下释放出来。此时,操作系统将回收内存,操作系统可能会决定在那里存储其他内容。尝试打开 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.