Challenge
Your challenge is to add a new “Closet” class to the demo project, using manual memory management, so that this code works:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
Person *ray = [[Person alloc] initWithName:@"Ray"];
Person *vicki = [[Person alloc] initWithName:@"Vicki"];
Closet *closet = [[Closet alloc] init];
ray.sweater = closet.graySweaterSlot;
closet.graySweaterSlot = nil;
vicki.sweater = closet.blueSweaterSlot;
closet.blueSweaterSlot = nil;
closet.blueSweaterSlot = vicki.sweater;
vicki.sweater = ray.sweater;
ray.sweater = nil;
[ray release];
[vicki release];
[closet release];
return YES;
}
Download demo code
Download solution
Helpful links
Errata
- Around 8:28, I said “you always have to call super dealloc first”. This is a bit confusing, because actually it’s best practice to put the call to [super dealloc] at the end of the method, as shown in the video. It would have been more clear if I had said “you always have to call super dealloc at the end of dealloc if you are not using ARC”.
- Audio was cut off around the 15:00 mark – it should have said “when you call init, by convention, it returns an object with retain count of 1”.