I am trying to better understand when to properly release an object in a fairly memory intensive program. My current doubt arises from the following bit of code:
- (void)scrollViewDidScroll:(UIScrollView *)localScrollView
{
InteractionPointModel *model = [[InteractionPointModel alloc] init];
for (int x=0; x<totalInteractionPoints; x++) {
model = [interactionPointData objectAtIndex:x];
CGPoint oldCenter = model->worldLocation;
CGPoint newCenter;
newCenter.x = oldCenter.x * [localScrollView zoomScale];
newCenter.y = oldCenter.y * [localScrollView zoomScale];
[[interactionPoints objectAtIndex:x] setCenter:newCenter];
}
[model release];
}
I would have thought that the program was done with model by now, but it crashes upon release. If I don't release it, the program runs, but obviously with a memory leak. What am I doing wrong?