我想更好地理解何時在相當內存密集的程序中正確釋放對象。我現在懷疑源於下面的代碼位:何時正確釋放對象
- (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];
}
我本來以爲該方案是由現用模型做的,但它崩潰後釋放。如果我沒有釋放它,程序會運行,但顯然會發生內存泄漏。我究竟做錯了什麼?
我開始覺得問題出現在interactionPointData中,因爲這個方法並不擁有它。既然我用模型指出它,釋放模型會造成嚴重的上游嗎? – diatrevolo 2010-09-15 04:30:12