另一个 EXC_BAD_ACCESS - 但是对于僵尸(仪器),永远不会 exe_bad_access

发布于 2024-11-25 07:19:32 字数 2580 浏览 1 评论 0原文

我花了几个小时研究这个问题,并阅读了网上有关内存管理、僵尸的所有内容。泄漏(尝试过的仪器)。但我无法弄清楚这一点。有人有线索吗?我在弹出 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 技术交流群。

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

发布评论

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

评论(1

黄昏下泛黄的笔记 2024-12-02 07:19:32

您在示例中首先调用 [super dealloc]; 。这应该始终是最后一次调用,否则您将访问属于现已释放的类的实例变量。如果您在其他地方遵循内存管理规则,则以下内容应该可以正常工作。

- (void) dealloc
{
   [profileVO release];

   [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.

- (void) dealloc
{
   [profileVO release];

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