我将 ARC 与 xCode 4.6 一起使用,并且在尝试访问.notes
an 的属性EKEvent
以分配给cellForRowAtIndexPath
.
有趣的是,直到我在任何不cellForRowAtIndexPath
调用EKEvents
.
根据 Instruments 的说法,泄漏的发生是因为这条线:
eventNotes = [NSString stringWithFormat:@"%@", [currentEvent notes]];
eventNotes
是ivar
我在我的 .h 文件中声明的。
我已经尝试了以下同时使用ivar
和动态创建一个新的实例变量,但似乎没有任何效果:
NSString *eventNotes = [NSString stringWithFormat:@"%@", [currentEvent notes]];
eventNotes = [currentEvent notes];
eventNotes = currentEvent.notes;
NSString *eventNotes = [currentEvent notes];
NSString *eventNotes = currentEvent.notes;
NSString *eventNotes = [NSString stringWithString:[currentEvent notes]];
NSString *eventNotes = [NSString stringWithString:currentEvent.notes];
eventNotes = [NSString stringWithString:currentEvent.notes];
名单还在继续,这是我的 cellForRowAtIndexPathCode,发生泄漏的地方。我对内存管理完全陌生,所以请!是描述性的。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
//Custom Cell...
UTATableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
cell.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"tableviewCell.png"]];
cell.textLabel.backgroundColor = [UIColor clearColor];
cell.detailTextLabel.backgroundColor = [UIColor clearColor];
//reset cell view attributes
cell.paidButton.tag = 1;
[cell.paidButton setAlpha:1.0f];
[cell.paidButton setSelected:NO];
[cell.paidButton setEnabled:YES];
cell.title.tag = 2;
cell.title.text = NULL;
cell.subtitle.tag = 3;
cell.subtitle.text = NULL;
[cell.paidButton addTarget:self action:@selector(togglePaid:) forControlEvents:UIControlEventTouchUpInside];
if ([_yearSwitcher selectedSegmentIndex] == 0) {
//lastYearsUTAEvents is an MSMutable array and a property of sharedEventData, which is a singleton class...
NSMutableArray *currentArray = [sharedEventData.lastYearsUTAEvents objectAtIndex:indexPath.section];
EKEvent *currentEvent = [currentArray objectAtIndex:indexPath.row];
NSDate *date = [currentEvent startDate];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateStyle:NSDateFormatterMediumStyle];
[dateFormatter setTimeStyle:NSDateFormatterNoStyle];
NSString *dateString = [dateFormatter stringFromDate:date];
cell.title.text = dateString;
-leak---> eventNotes = [NSString stringWithFormat:@"%@", [currentEvent notes]];
if ([eventNotes rangeOfString:@" - Paid"].location != NSNotFound) {
cell.subtitle.text = [eventNotes stringByReplacingOccurrencesOfString:@" - Paid" withString:@""];
[cell.paidButton setSelected:YES];
} else {
cell.subtitle.text = eventNotes;
[cell.paidButton setSelected:NO];
}
} else {
// same as above but different array....
}
return cell;
}