另一个 EXC_BAD_ACCESS - 但是对于僵尸(仪器),永远不会 exe_bad_access
我花了几个小时研究这个问题,并阅读了网上有关内存管理、僵尸的所有内容。泄漏(尝试过的仪器)。但我无法弄清楚这一点。有人有线索吗?我在弹出 ChildViewController 时收到类似以下代码的 EXC_BAD_ACCESS 。
[profileVO release]; profileVO = nil;
我强烈地感觉到我已经遵循了所有内存管理最佳实践!
详细信息:
我有一个模型文件。 (CachedProfileVO)
CachedProfileVO.h
@interface CachedProfileVO : NSObject {
NSString *name;
NSString *email;
}
@property (nonatomic, retain) NSString *name;
@property (nonatomic, retain) NSString *email;
@end
CachedProfileVO.m
@synthesize name, email;
- (void) dealloc
{
[super dealloc];
[name release]; name= nil;
[email release]; email = nil;
}
现在我有了一个 UINavigationController。 ParentViewController 和 ChildViewController。 我按如下方式调用 ChildViewController:
[self.navigationCntroller pushViewcontroller:childViewcontroller animated:YES];
在 ChildViewController 中,我基本上使用模型 CachedProfileVO。但是,当弹出此视图控制器(UI 上的后退按钮)时,它会给出 EXC_BAD_ACCESS
ChildViewController.h
@interface ChildViewcontroller : UITableViewController {
CachedProfileVO *profileVO;
}
@property (nonatomic, retain) CachedProfileVO *profileVO;
@end
ChildViewController.m
@synthesize profileVO;
- (void) dealloc
{
[super dealloc];
[profileVO release]; profileVO = nil; ****** GETTING EXE_BAD_ACCESS here
}
- (void) viewDidLoad
{
CachedProfileVO *vo = [CachedProfileVO alloc] init];
self.profileVO = vo;
[vo release];
}
//responseString looks like this: [Murdoch, [email protected]][other data][more data]
- (void) populateProfile:(NSString *) responseString
{
NSMutableString *str = [[NSMutableString alloc] initWithCapacity:20];
[str setString:responseString];
[str deleteCharactersInRange: NSMakeRange(0,1)];
[str deleteCharactersInRange: NSMakeRange([str length]-1,1)];
NSArray *tempArray = [str componentsSeparatedByString: @"]["];
NSString *tempStr = (NSString*)[tempArray objectAtIndex:0];
NSArray *bioArray = [tempStr componentsSeparatedByString:@","];
self.profileVO.name = (NSString*)[bioArray objectAtIndex:0];
self.profileVO.email= (NSString*)[bioArray objectAtIndex:1];
[str release]; str = nil;
}
请注意,函数 populateProfile 在某个事件后被调用。我知道它叫。然后 dealloc 就会导致问题。而且这并不是在每个流行音乐中都会发生。我必须尝试多次才能重现。它永远不会在乐器中使用僵尸来再现!
I have spent hours on this and read everybit on the web about memory management, zombies. leaks (tried instruments). But I cannot figure this one out. Does someone has a clue? I am getting a EXC_BAD_ACCESS at the following like of code on popping the ChildViewController.
[profileVO release]; profileVO = nil;
I strongly feel I have followed all memory management best practices!
Details:
I have a model file. (CachedProfileVO)
CachedProfileVO.h
@interface CachedProfileVO : NSObject {
NSString *name;
NSString *email;
}
@property (nonatomic, retain) NSString *name;
@property (nonatomic, retain) NSString *email;
@end
CachedProfileVO.m
@synthesize name, email;
- (void) dealloc
{
[super dealloc];
[name release]; name= nil;
[email release]; email = nil;
}
Now I have a UINavigationController. The ParentViewController and the ChildViewController.
I invoke the ChildViewController as follows:
[self.navigationCntroller pushViewcontroller:childViewcontroller animated:YES];
In the ChildViewController, I basically use the model CachedProfileVO. However when this view controller is popped (back button on UI), it gives a EXC_BAD_ACCESS
ChildViewController.h
@interface ChildViewcontroller : UITableViewController {
CachedProfileVO *profileVO;
}
@property (nonatomic, retain) CachedProfileVO *profileVO;
@end
ChildViewController.m
@synthesize profileVO;
- (void) dealloc
{
[super dealloc];
[profileVO release]; profileVO = nil; ****** GETTING EXE_BAD_ACCESS here
}
- (void) viewDidLoad
{
CachedProfileVO *vo = [CachedProfileVO alloc] init];
self.profileVO = vo;
[vo release];
}
//responseString looks like this: [Murdoch, [email protected]][other data][more data]
- (void) populateProfile:(NSString *) responseString
{
NSMutableString *str = [[NSMutableString alloc] initWithCapacity:20];
[str setString:responseString];
[str deleteCharactersInRange: NSMakeRange(0,1)];
[str deleteCharactersInRange: NSMakeRange([str length]-1,1)];
NSArray *tempArray = [str componentsSeparatedByString: @"]["];
NSString *tempStr = (NSString*)[tempArray objectAtIndex:0];
NSArray *bioArray = [tempStr componentsSeparatedByString:@","];
self.profileVO.name = (NSString*)[bioArray objectAtIndex:0];
self.profileVO.email= (NSString*)[bioArray objectAtIndex:1];
[str release]; str = nil;
}
Note that the function populateProfile is called after some event. I know it is called. And dealloc then causes the problem. Also this does not happen in every pop. I have to try several times to reproduce. It is never reproduced using zombies in instruments!!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您在示例中首先调用
[super dealloc];
。这应该始终是最后一次调用,否则您将访问属于现已释放的类的实例变量。如果您在其他地方遵循内存管理规则,则以下内容应该可以正常工作。You are calling
[super dealloc];
first in your examples. That should always be the last call otherwise you are accessing instance variables that belong to a now deallocated class. The following should work fine if you followed memory management rules elsewhere.