저는 코코아/objective-c에 익숙하지 않습니다. 저는 제 물건들을 풀어 가려고 애 쓰고 있습니다.forin 루프에서 객체를 해제하는 방법은 무엇입니까?
gastroCategoryList = [[NSMutableArray alloc] init];
for (NSDictionary *gastrocategory in gastrocategories) {
NSString *oid = [gastrocategory objectForKey:@"id"];
GastroCategory *gc = [[GastroCategory alloc] initWithId:[oid intValue] name:[gastrocategory objectForKey:@"name"]];
[gastroCategoryList addObject:gc];
}
분석기는 대한에 정의 된 "gastrocategory는"잠재적 메모리 누수입니다 내게 보여줍니다 나는 다음과 같은 코드가 있습니다. 하지만 for 루프의 끝에서 이걸 공개 할 수 있을지 모르겠습니다. 다음 코드에서 또한
:
- (NSArray *)eventsForStage:(int)stageId {
NSMutableArray *result = [[NSMutableArray alloc] init];
for (Event *e in eventList) {
if ([e stageId] == stageId) {
[result addObject:e];
}
}
return result;
}
분석기는 내 "결과가"잠재적 인 누출 것을 알려줍니다. 그러나 나는 이것을 어디에서 풀어야합니까?
@property에서 할당, 복사, 보존 등을 사용해야 할 때를 암기하는 간단한 규칙이 있습니까?
또 다른 문제 :
- (IBAction)showHungryView:(id)sender {
GastroCategoriesView *gastroCategoriesView = [[GastroCategoriesView alloc] initWithNibName:@"GastroCategoriesView" bundle:nil];
[gastroCategoriesView setDataManager:dataManager];
UIView *currentView = [self view];
UIView *window = [currentView superview];
UIView *gastroView = [gastroCategoriesView view];
[window addSubview:gastroView];
CGRect pageFrame = currentView.frame;
CGFloat pageWidth = pageFrame.size.width;
gastroView.frame = CGRectOffset(pageFrame,pageWidth,0);
[UIView beginAnimations:nil context:NULL];
currentView.frame = CGRectOffset(pageFrame,-pageWidth,0);
gastroView.frame = pageFrame;
[UIView commitAnimations];
//[gastroCategoriesView release];
}
가 나는 그것을 얻지 않는다는 "gastroCategoriesView는"잠재적 인 누출이다. 나는 그것을 끝내거나 autorelease로 풀려고했지만 둘 다 잘 동작하지 않습니다. 매번 메소드를 호출하면 앱이 종료됩니다. 대단히 감사합니다! 루프에서
대단히 감사합니다. @property 문제에 대한 규칙도 알고 있습니까? – n3on
@ n3on : 속성이'retain' 또는'copy'라고 선언되면 클래스의'dealloc' 메소드에서 ivar를 해제해야합니다. – BoltClock
@BoltClock : 감사합니다. 그러나 언제 사본을 사용해야합니까? – n3on