madcoderz
madcoderz

Reputation: 4431

instruments won't find any leaks iphone

I'm trying to learn how instruments work, to do that i created a small project with a leak to see if it shows up in the Instruments but it's not showing up. The code i have to create the leak is the following:

-(IBAction)leakme
{
    self.leaked = [[NSString alloc]init];
    self.leaked2 = [[NSString alloc]init];
    self.leaked3 = [[NSString alloc]init];

    leaked = @"John";
    leaked2 = @"Anderson";
    leaked3 = @"Smith";
}

That doesn't show any leaks. As the application never reaches the dealloc method i did the following:

-(IBAction)nilit
{
    self.leaked = nil;
    self.leaked2 = nil;
    self.leaked3 = nil;
}

But still no leaks are shown. What i'm i missing here?

Thanks.

Upvotes: 1

Views: 74

Answers (1)

bbum
bbum

Reputation: 162712

You aren't actually causing anything to be allocated; NSString is optimized internally such that [[NSString alloc] init] returns a singleton.

Either use NSMutableString or use a class of your own creation (better).

Upvotes: 8

Related Questions