저는 첫 번째 큰 응용 프로그램에 있는데 여기 메모리 관리에 약간의 문제가 있습니다.IOS 개발, if 및 else 및 autorelease를 사용하는 return 함수
-(id) dateFormatter:(id)date{
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setTimeStyle:NSDateFormatterShortStyle];
[dateFormatter setDateStyle:NSDateFormatterLongStyle];
if([date isKindOfClass:[NSString class]])
return [dateFormatter dateFromString:date];
else
return [dateFormatter stringFromDate:date];
}
자, 내가 본 것처럼,이 예제의 모든 리턴은 결국 자동 릴리즈가 필요합니다. 하지만 autorelease를 추가 할 때 EXC_BAD_ACCESS 오류가 발생하고 모든 것이 잘 작동합니다. 내가 문제를 분석하고 너무 많은 autorelease 함수에있어,하지만 어떻게 그것을 NSDateFormatter없이 메모리를 해제 할 수 있습니다 볼 수 없습니다.
아무도 설명 할 수 있습니까?
물론 할 수 있습니다.하지만 시도한 방식과 다릅니다. 고맙습니다. 이것은 명백한 방법입니다. 그리고 이것이 이것이 할 수있는 방법이라면, 그것은 내가 할 일입니다 :-) – Erez
잘못된 객체에'autorelease'를 추가하는 것처럼 보입니다. 귀하의 질문에, 나는 당신이하고있는 수집 :'[[dateFormatter dateFromString : date] autorelease];'당신은 그것을 입고 있었어야했다 :'[[NSDateFormatter alloc] init] autorelease];' –