为什么我得到一个EXC_BAD_ACCES

For*_*est 0 iphone twitter objective-c

嘿.我一直在研究Twitter应用程序,并且已经在EXC_ BAD_ ACCESS错误上停留了很长时间.我知道EXC_ BAD_ ACCESS是一个内存问题,但我无法确定问题所在.这是我的代码示例:

- (void)viewDidLoad {
   [super viewDidLoad];

   NSString *path = @"/Volumes/Schools/BHS/Student/740827/Documents/Forrest McIntyre CS193P/Presence2";
   NSArray *propList = [NSArray arrayWithContentsOfFile:[NSBundle pathForResource:@"TwitterUsers" ofType:@"plist" inDirectory:path]];

   people = [[NSMutableArray alloc]init];

   for (NSString *name in propList) {
     Person *p = [[Person alloc] initWithUserName: name];
     [people addObject: p];
     [p release];
   }
   // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
   // self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
Run Code Online (Sandbox Code Playgroud)

注释后的最后一个大括号抛出异常.我相信它确实被扔进了某个地方的for循环中,但只是出现了.

这是Person的实现文件:

@implementation Person
@synthesize image;
@synthesize username;
@synthesize displayName;
@synthesize statusArray;

-(id)initWithUserName:(NSString *)userName {
 if(self = [super init])
 {
  self.username = userName;
  NSDictionary *info = [TwitterHelper fetchInfoForUsername:userName];
  self.displayName = [info objectForKey:@"name"];
  NSLog([NSString stringWithFormat:@"%@",[info objectForKey:@"profile_image_url"]]);
  NSString *imageURL2 = [NSString stringWithFormat:@"%@",[info objectForKey:@"profile_image_url"]];
  self.image = [UIImage imageWithData: [NSData dataWithContentsOfURL: [NSURL URLWithString: imageURL2]]];
  [info release];
  self.statusArray = [TwitterHelper fetchTimelineForUsername:userName]; 
 }
 return self;
}
@end
Run Code Online (Sandbox Code Playgroud)

谢谢你的帮助

编辑:这是PersonListViewController的头文件(包含ViewDidLoad的类).这只是为了向您展示人们的来源.

@interface PersonListViewController : UITableViewController {
    NSMutableArray *people;
}

@end
Run Code Online (Sandbox Code Playgroud)

cob*_*bal 9

因为你永远不会保留,propList或者path你不应该释放它们.

但是,你应该释放 people

有关内存管理的概述,请参阅" 内存管理编程指南"

要快速修复,请尝试使用静态分析器.