Objective-C : memory leak or not with multiple assignation with autorelease?
-
25-09-2019 - |
문제
If I do the following thing, will this make memory leaks ?
SomeClass* tmp;
NSDate* thetmpdate;
tmp = [[[SomeClass alloc] init] autorelease];
thetmpdate = [NSDate date];
// Do something long with tmp and date
tmp = [[[SomeClass alloc] init] autorelease];
thetmpdate = [NSDate date];
// Do something long with tmp and date
tmp = [[[SomeClass alloc] init] autorelease];
thetmpdate = [NSDate date];
// Do something long with tmp and date
해결책
No, there's no leak in the code you posted. All objects will be autoreleased when the autorelease pool is flushed, no matter if the variable holding their pointers is changed or not.
제휴하지 않습니다 StackOverflow