2011-01-05 11 views
1

Wenn ich die folgende Sache mache, macht dies Speicherlecks?Objective-C: Speicherleck oder nicht mit Mehrfachzuweisung mit Autorelease?

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 

Antwort

6

Nein, der von Ihnen gepostete Code ist nicht undicht. Alle Objekte werden automatisch freigegeben, wenn der Autorelease-Pool geleert wird, unabhängig davon, ob die Variable, die ihre Zeiger enthält, geändert wird oder nicht.