Information Technology Reference
In-Depth Information
Managing zombies
Unfortunately, there's no way to view objects that have been freed; after they're gone, they're gone, and they no
longer appear in any of the statistics. When you release an event and send a message to it, it becomes a zom-
bie— an undead object that haunts memory and tries to eat your Mac or iPhone's brain. Because manual
memory management is so tricky, Instruments include a special zombie monitoring tool to help you capture
zombies before they get out of hand.
To illustrate this, the next example uses bad code to deliberately create a zombie and demonstrate how Instru-
ments can highlight its location. Create a new Window-based iOS application, or modify the one you made
earlier, changing the code in the app delegate to this listing:
#import “ZombiesAppDelegate.h”
@implementation ZombiesAppDelegate
NSObject *theZombie;
@synthesize window;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOp-
tions:(NSDictionary *)launchOptions
{
[self.window makeKeyAndVisible];
NSTimer *theTimer =
[NSTimer scheduledTimerWithTimeInterval:1.0
target:self
selector:@selector(timerDo)
userInfo:nil
repeats:YES];
Search WWH ::




Custom Search