Instruments doesn't detect memory leak

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

  1. namanhams macrumors regular

    Jun 3, 2009
    Hi guys,

    I have the following code inside an UIViewController :

    - (void) 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

    Jun 22, 2010
    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

    Jun 3, 2009

    I'm running on the Simulator.

    I still can not figure out why.

Share This Page