---- MyEventSelectorCell.h
@interface MyEventSelectorCell : UITableViewCell {
IBOutlet UIImageView* eventImage;
}
@property(nonatomic, retain) IBOutlet UIImageView* anImage;
----- MyEventSelectorCell.m
-(id) dealloc {
[anImage release];// < -- If I comment this out, It starts leaking, but program runs fine...
}
---- MyTableViewController.h
@MyTableViewController: UIViewController<UITableViewDelegate> {
IBOutlet MyEventSelectorCell* tmpCell;
}
@property(nonatomic, retain) IBOutlet MyEvent开发者_开发百科SelectorCell* tmpCell;
---- MyTableViewController.m
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
...
[[NSBundle mainBundle] loadNibNamed:@"MyEventSelectorCell" owner:self options:nil];
tmpCell.anImage.image = [UIImage imageNamed: @"someimage.png"];
...
}
EXC_BAD_ACCESS happens after I release anImage when setting the UIImageView .image property to imageNamed above...
[UIImage imagedNamed:...] returns a autorelease object. So, if you release too you have to retain explicitly:
tmpCell.anImage.image = [[UIImage imageNamed: @"someimage.png"] retain];
Hope that helps you. Cheers.
R31n4ld0 is technically correct, but since UIImageView retains its image, you shouldn't explicitly retain it yourself.
Your issue may be occurring because you're releasing a view thats retained by a property with the "retain" attribute. Synthesized "retain" properties include implicit calls to release and retain in the setter, so the usual pattern in dealloc is to assign them nil instead of calling release on the property itself. This prevents redundant release calls upon reassignment of the property.
精彩评论