Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

namanhams

macrumors regular
Original poster
Jun 3, 2009
153
0
Hi guys,

I have the following code inside an UIViewController :

Code:
- (void) viewDidLoad {
    NSLog(@"viewDidLoad");
    [super viewDidLoad];
    button = [[UIButton alloc] init];
    [self.view addSubview:button];
}

When i generate a memory warning, this UIViewController's view will be unloaded. (i know it because i print out inside viewDidUnload method). The 'button' is still there, since we keep a reference to it.

The problem is, when the viewDidLoad is called again, we assign 'button' to a new UIButton created, then there should be a memory leak. But the Instruments app doesn't detect this leak.

I have no idea why. Any one ?
 
Are you running Instruments on the simulator or on the hardware?

I find both somewhat unreliable.
  • Sometimes the detail pane does not show latest information. It seems to refresh if you choose "Console" from the drop-down menu, then return to "Leaked Blocks" or "Call Tree". Or, click on Allocations time-line, then switch back to Leaks time-line.
  • Sometimes some leaks are simply not detected. For example the code was set-up to leak a UIButton whenever the screen was tapped: 16 taps, and Instruments registered 3 UIButton leaks. Some minutes later, Instruments now shows 5 UIButton leaks.

(XCode 3.2.3, iOS 4.0.2 SDK.)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.