Instruments doesn't detect memory leak

Discussion in 'iOS Programming' started by namanhams, Aug 25, 2010.

  1. namanhams macrumors regular

    Joined:
    Jun 3, 2009
    #1
    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 ?
     
  2. ianray macrumors 6502

    Joined:
    Jun 22, 2010
    Location:
    @
    #2
    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.)
     
  3. namanhams thread starter macrumors regular

    Joined:
    Jun 3, 2009
    #3
    Hi,

    I'm running on the Simulator.

    I still can not figure out why.
     

Share This Page