Resolved Memory disappearing .. Quartz Core.. actually NSTimer!

Discussion in 'iOS Programming' started by IDMah, Apr 22, 2014.

  1. IDMah, Apr 22, 2014
    Last edited: Apr 23, 2014

    IDMah macrumors 6502

    IDMah

    Joined:
    May 13, 2011
    #1
    Trying to track this down.

    As my app runs It seems to be eating more and more memory, as it runs.
    I've disabled All NSTimer scheduledTimerWithTimeInterval calls
    Yet still loosing about 1meg every 1 second so you can see I'm pretty desperate
    to find this..

    thanks
    Ian

    Instruments ( Allocations ) says:

    Code:
    #	Address	Category	Timestamp	Live	Size	Responsible Library	Responsible Caller
    
    27518	0xd1e5f80	Malloc 16 Bytes	00:06.483.587	•	16 Bytes	QuartzCore	mem_alloc
    27519	0xd1e5f00	Malloc 16 Bytes	00:06.483.593	•	16 Bytes	QuartzCore	mem_alloc
    27520	0xc7c5be8	Malloc 8 Bytes	00:06.483.595	•	8 Bytes	QuartzCore	mem_alloc
    27521	0xd1e5e80	Malloc 16 Bytes	00:06.483.596	•	16 Bytes	QuartzCore	mem_alloc
    27522	0xd1e5e00	Malloc 16 Bytes	00:06.483.598	•	16 Bytes	QuartzCore	mem_alloc
    27523	0x11410e08	Malloc 52 Bytes	00:06.483.604	•	52 Bytes	QuartzCore	mem_alloc
    27524	0xd1e5d80	Malloc 16 Bytes	00:06.483.605	•	16 Bytes	QuartzCore	mem_alloc
    27525	0x113c81c0	Malloc 32 Bytes	00:06.483.626	•	32 Bytes	QuartzCore	mem_alloc
    27526	0xd1e5d00	Malloc 16 Bytes	00:06.483.627	•	16 Bytes	QuartzCore	mem_alloc
    27527	0xd1e5c80	Malloc 16 Bytes	00:06.483.691	•	16 Bytes	QuartzCore	mem_alloc
    27528	0xd1e5c00	Malloc 16 Bytes	00:06.483.694	•	16 Bytes	QuartzCore	mem_alloc
    27529	0xd1e5b80	Malloc 16 Bytes	00:06.483.697	•	16 Bytes	QuartzCore	mem_alloc
    27530	0xd1e5b00	Malloc 16 Bytes	00:06.483.700	•	16 Bytes	QuartzCore	mem_alloc
    27531	0xd1e5a80	Malloc 16 Bytes	00:06.483.702	•	16 Bytes	QuartzCore	mem_alloc
    27532	0xd1e5a00	Malloc 16 Bytes	00:06.483.704	•	16 Bytes	QuartzCore	mem_alloc
    27533	0xd1e5980	Malloc 16 Bytes	00:06.483.707	•	16 Bytes	QuartzCore	mem_alloc
    27534	0xd1e5900	Malloc 16 Bytes	00:06.483.709	•	16 Bytes	QuartzCore	mem_alloc
    27535	0xd1e5880	Malloc 16 Bytes	00:06.483.712	•	16 Bytes	QuartzCore	mem_alloc
    27536	0xd1e5800	Malloc 16 Bytes	00:06.483.714	•	16 Bytes	QuartzCore	mem_alloc
    27537	0xd1e5780	Malloc 16 Bytes	00:06.483.717	•	16 Bytes	QuartzCore	mem_alloc
    27538	0xd1e5700	Malloc 16 Bytes	00:06.483.719	•	16 Bytes	QuartzCore	mem_alloc
    27539	0xd1e5680	Malloc 16 Bytes	00:06.483.721	•	16 Bytes	QuartzCore	mem_alloc
    27540	0xd1e5600	Malloc 16 Bytes	00:06.483.724	•	16 Bytes	QuartzCore	mem_alloc
    27541	0xd1e5580	Malloc 16 Bytes	00:06.483.727	•	16 Bytes	QuartzCore	mem_alloc
    27542	0xd1e5500	Malloc 16 Bytes	00:06.483.729	•	16 Bytes	QuartzCore	mem_alloc
    27543	0xd1e5480	Malloc 16 Bytes	00:06.483.732	•	16 Bytes	QuartzCore	mem_alloc
    27544	0xd1e5400	Malloc 16 Bytes	00:06.483.734	•	16 Bytes	QuartzCore	mem_alloc
    27545	0xd1e5380	Malloc 16 Bytes	00:06.483.737	•	16 Bytes	QuartzCore	mem_alloc
    27546	0xd1e5300	Malloc 16 Bytes	00:06.483.740	•	16 Bytes	QuartzCore	mem_alloc
    27547	0xd1e5280	Malloc 16 Bytes	00:06.483.743	•	16 Bytes	QuartzCore	mem_alloc
    27548	0xd1e5200	Malloc 16 Bytes	00:06.483.745	•	16 Bytes	QuartzCore	mem_alloc
    27549	0xd1e5180	Malloc 16 Bytes	00:06.483.748	•	16 Bytes	QuartzCore	mem_alloc
    27550	0xd1e5100	Malloc 16 Bytes	00:06.483.751	•	16 Bytes	QuartzCore	mem_alloc
    27551	0xd1e5080	Malloc 16 Bytes	00:06.483.753	•	16 Bytes	QuartzCore	mem_alloc
    27552	0x11411ff0	Malloc 16 Bytes	00:06.483.766	•	16 Bytes	QuartzCore	mem_alloc
    27553	0x11411f70	Malloc 16 Bytes	00:06.483.769	•	16 Bytes	QuartzCore	mem_alloc
    27554	0x11411ef0	Malloc 16 Bytes	00:06.483.772	•	16 Bytes	QuartzCore	mem_alloc
    27555	0x11411e70	Malloc 16 Bytes	00:06.483.774	•	16 Bytes	QuartzCore	mem_alloc
    27556	0x11411df0	Malloc 16 Bytes	00:06.483.777	•	16 Bytes	QuartzCore	mem_alloc
    27557	0x11411d70	Malloc 16 Bytes	00:06.483.779	•	16 Bytes	QuartzCore	mem_alloc
    27558	0x11411cf0	Malloc 16 Bytes	00:06.483.782	•	16 Bytes	QuartzCore	mem_alloc
    27559	0x11411c70	Malloc 16 Bytes	00:06.483.785	•	16 Bytes	QuartzCore	mem_alloc
    27560	0x11411bf0	Malloc 16 Bytes	00:06.483.787	•	16 Bytes	QuartzCore	mem_alloc
    27561	0x11411b70	Malloc 16 Bytes	00:06.483.790	•	16 Bytes	QuartzCore	mem_alloc
    27562	0x11411af0	Malloc 16 Bytes	00:06.483.793	•	16 Bytes	QuartzCore	mem_alloc
    27563	0x11411a70	Malloc 16 Bytes	00:06.483.795	•	16 Bytes	QuartzCore	mem_alloc
    27564	0x114119f0	Malloc 16 Bytes	00:06.483.798	•	16 Bytes	QuartzCore	mem_alloc
    27565	0x11411970	Malloc 16 Bytes	00:06.483.800	•	16 Bytes	QuartzCore	mem_alloc
    27566	0x114118f0	Malloc 16 Bytes	00:06.483.803	•	16 Bytes	QuartzCore	mem_alloc
    27567	0x11411870	Malloc 16 Bytes	00:06.483.805	•	16 Bytes	QuartzCore	mem_alloc
    27568	0x114117f0	Malloc 16 Bytes	00:06.483.808	•	16 Bytes	QuartzCore	mem_alloc
    27569	0x11411770	Malloc 16 Bytes	00:06.483.810	•	16 Bytes	QuartzCore	mem_alloc
    27570	0x114116f0	Malloc 16 Bytes	00:06.483.813	•	16 Bytes	QuartzCore	mem_alloc
    27571	0x11411670	Malloc 16 Bytes	00:06.483.816	•	16 Bytes	QuartzCore	mem_alloc
    27572	0x114115f0	Malloc 16 Bytes	00:06.483.818	•	16 Bytes	QuartzCore	mem_alloc
    27573	0x11411570	Malloc 16 Bytes	00:06.483.821	•	16 Bytes	QuartzCore	mem_alloc
    27574	0x114114f0	Malloc 16 Bytes	00:06.483.824	•	16 Bytes	QuartzCore	mem_alloc
    27575	0x11411470	Malloc 16 Bytes	00:06.483.826	•	16 Bytes	QuartzCore	mem_alloc
    27576	0x114113f0	Malloc 16 Bytes	00:06.483.829	•	16 Bytes	QuartzCore	mem_alloc
    27577	0x11411370	Malloc 16 Bytes	00:06.483.834	•	16 Bytes	QuartzCore	mem_alloc
    27578	0x114112f0	Malloc 16 Bytes	00:06.483.836	•	16 Bytes	QuartzCore	mem_alloc
    27579	0x11411270	Malloc 16 Bytes	00:06.483.839	•	16 Bytes	QuartzCore	mem_alloc
    27580	0x114111f0	Malloc 16 Bytes	00:06.483.841	•	16 Bytes	QuartzCore	mem_alloc
    27581	0x11411170	Malloc 16 Bytes	00:06.483.844	•	16 Bytes	QuartzCore	mem_alloc
    27582	0x114110f0	Malloc 16 Bytes	00:06.483.846	•	16 Bytes	QuartzCore	mem_alloc
    27583	0x11411070	Malloc 16 Bytes	00:06.483.849	•	16 Bytes	QuartzCore	mem_alloc
    27584	0x11411fe0	Malloc 16 Bytes	00:06.483.851	•	16 Bytes	QuartzCore	mem_alloc
    27585	0x11411f60	Malloc 16 Bytes	00:06.483.854	•	16 Bytes	QuartzCore	mem_alloc
    27586	0x11411ee0	Malloc 16 Bytes	00:06.483.856	•	16 Bytes	QuartzCore	mem_alloc
    27587	0x11411e60	Malloc 16 Bytes	00:06.483.859	•	16 Bytes	QuartzCore	mem_alloc
    27588	0x11411de0	Malloc 16 Bytes	00:06.483.861	•	16 Bytes	QuartzCore	mem_alloc
    27589	0x11411d60	Malloc 16 Bytes	00:06.483.864	•	16 Bytes	QuartzCore	mem_alloc
    27590	0x11411ce0	Malloc 16 Bytes	00:06.483.867	•	16 Bytes	QuartzCore	mem_alloc
    27591	0x11411c60	Malloc 16 Bytes	00:06.483.869	•	16 Bytes	QuartzCore	mem_alloc
    27592	0x11411be0	Malloc 16 Bytes	00:06.483.872	•	16 Bytes	QuartzCore	mem_alloc
    27593	0x11411b60	Malloc 16 Bytes	00:06.483.874	•	16 Bytes	QuartzCore	mem_alloc
    27594	0x11411ae0	Malloc 16 Bytes	00:06.483.877	•	16 Bytes	QuartzCore	mem_alloc
    27595	0x11411a60	Malloc 16 Bytes	00:06.483.879	•	16 Bytes	QuartzCore	mem_alloc
    27596	0x114119e0	Malloc 16 Bytes	00:06.483.881	•	16 Bytes	QuartzCore	mem_alloc
    27597	0x11411960	Malloc 16 Bytes	00:06.483.884	•	16 Bytes	QuartzCore	mem_alloc
    27598	0x114118e0	Malloc 16 Bytes	00:06.483.886	•	16 Bytes	QuartzCore	mem_alloc
    27599	0x11411860	Malloc 16 Bytes	00:06.483.889	•	16 Bytes	QuartzCore	mem_alloc
    27600	0x114117e0	Malloc 16 Bytes	00:06.483.891	•	16 Bytes	QuartzCore	mem_alloc
    27601	0x11411760	Malloc 16 Bytes	00:06.483.894	•	16 Bytes	QuartzCore	mem_alloc
    27602	0x114116e0	Malloc 16 Bytes	00:06.483.897	•	16 Bytes	QuartzCore	mem_alloc
    27603	0x11411660	Malloc 16 Bytes	00:06.483.899	•	16 Bytes	QuartzCore	mem_alloc
    27604	0x114115e0	Malloc 16 Bytes	00:06.483.902	•	16 Bytes	QuartzCore	mem_alloc
    27605	0x11411560	Malloc 16 Bytes	00:06.483.905	•	16 Bytes	QuartzCore	mem_alloc
    27606	0x114114e0	Malloc 16 Bytes	00:06.483.907	•	16 Bytes	QuartzCore	mem_alloc
    27607	0x11411460	Malloc 16 Bytes	00:06.483.910	•	16 Bytes	QuartzCore	mem_alloc
    27608	0x114113e0	Malloc 16 Bytes	00:06.483.912	•	16 Bytes	QuartzCore	mem_alloc
    27609	0x11411360	Malloc 16 Bytes	00:06.483.915	•	16 Bytes	QuartzCore	mem_alloc
    27610	0x114112e0	Malloc 16 Bytes	00:06.483.917	•	16 Bytes	QuartzCore	mem_alloc
    27611	0x11411260	Malloc 16 Bytes	00:06.483.920	•	16 Bytes	QuartzCore	mem_alloc
    27612	0x114111e0	Malloc 16 Bytes	00:06.483.922	•	16 Bytes	QuartzCore	mem_alloc
    27613	0x11411160	Malloc 16 Bytes	00:06.483.925	•	16 Bytes	QuartzCore	mem_alloc
    27614	0x114110e0	Malloc 16 Bytes	00:06.483.927	•	16 Bytes	QuartzCore	mem_alloc
    27615	0x11411060	Malloc 16 Bytes	00:06.483.930	•	16 Bytes	QuartzCore	mem_alloc
    27616	0x11411fd0	Malloc 16 Bytes	00:06.483.933	•	16 Bytes	QuartzCore	mem_alloc
    27617	0x11411f50	Malloc 16 Bytes	00:06.483.935	•	16 Bytes	QuartzCore	mem_alloc
    27618	0x11411ed0	Malloc 16 Bytes	00:06.483.937	•	16 Bytes	QuartzCore	mem_alloc
    27619	0x11411e50	Malloc 16 Bytes	00:06.483.940	•	16 Bytes	QuartzCore	mem_alloc
    27620	0x11411dd0	Malloc 16 Bytes	00:06.483.942	•	16 Bytes	QuartzCore	mem_alloc
    27621	0x11411d50	Malloc 16 Bytes	00:06.483.945	•	16 Bytes	QuartzCore	mem_alloc
    27622	0x11411cd0	Malloc 16 Bytes	00:06.483.947	•	16 Bytes	QuartzCore	mem_alloc
    27623	0x11411c50	Malloc 16 Bytes	00:06.483.950	•	16 Bytes	QuartzCore	mem_alloc
    27624	0x11411bd0	Malloc 16 Bytes	00:06.483.952	•	16 Bytes	QuartzCore	mem_alloc
    27625	0x11411b50	Malloc 16 Bytes	00:06.483.955	•	16 Bytes	QuartzCore	mem_alloc
    27626	0x11411ad0	Malloc 16 Bytes	00:06.483.957	•	16 Bytes	QuartzCore	mem_alloc
    27627	0x11411a50	Malloc 16 Bytes	00:06.483.960	•	16 Bytes	QuartzCore	mem_alloc
    27628	0x114119d0	Malloc 16 Bytes	00:06.483.962	•	16 Bytes	QuartzCore	mem_alloc
    27629	0x11411950	Malloc 16 Bytes	00:06.483.965	•	16 Bytes	QuartzCore	mem_alloc
    27630	0x114118d0	Malloc 16 Bytes	00:06.483.967	•	16 Bytes	QuartzCore	mem_alloc
    27631	0x11411850	Malloc 16 Bytes	00:06.483.970	•	16 Bytes	QuartzCore	mem_alloc
    27632	0x114117d0	Malloc 16 Bytes	00:06.483.972	•	16 Bytes	QuartzCore	mem_alloc
    27633	0x11411750	Malloc 16 Bytes	00:06.483.975	•	16 Bytes	QuartzCore	mem_alloc
    27634	0x114116d0	Malloc 16 Bytes	00:06.483.977	•	16 Bytes	QuartzCore	mem_alloc
    27635	0x11411650	Malloc 16 Bytes	00:06.483.980	•	16 Bytes	QuartzCore	mem_alloc
    27636	0x114115d0	Malloc 16 Bytes	00:06.483.983	•	16 Bytes	QuartzCore	mem_alloc
    27637	0x11411550	Malloc 16 Bytes	00:06.483.985	•	16 Bytes	QuartzCore	mem_alloc
    27638	0x114114d0	Malloc 16 Bytes	00:06.483.988	•	16 Bytes	QuartzCore	mem_alloc
    27639	0x11411450	Malloc 16 Bytes	00:06.483.990	•	16 Bytes	QuartzCore	mem_alloc
    27640	0x114113d0	Malloc 16 Bytes	00:06.483.993	•	16 Bytes	QuartzCore	mem_alloc
    27641	0x10f33180	Malloc 256 Bytes	00:06.483.995	•	256 Bytes	QuartzCore	mem_alloc0
    
    
     
  2. IDMah thread starter macrumors 6502

    IDMah

    Joined:
    May 13, 2011
    #2
    Ok .. Commented out below and slow leak went away.
    but how do I get a repeating timer that doesn't eat tons of memory..
    Code:
    /*
    myTimer = [NSTimer scheduledTimerWithTimeInterval:(1-(4/12))
    	         target:self 
                     selector:@selector(updateTimer)
    		 repeats:YES];
    */     
    
    
     
  3. MorphingDragon, Apr 22, 2014
    Last edited: Apr 22, 2014

    MorphingDragon macrumors 603

    MorphingDragon

    Joined:
    Mar 27, 2009
    Location:
    The World Inbetween
    #3
    Are you using ARC?

    Run the updateTimer method several times in a loop and see if it leaks memory then.

    Another trick in the book is to wrap suspected [class new] calls into a macro that also prints what line of code and what file it is to the console.
     
  4. xStep macrumors 68000

    Joined:
    Jan 28, 2003
    Location:
    Less lost in L.A.
    #4
    Where's your code? What does it do? Is the work completed before the next call to method? Are you cleaning up from the previous call?

    How do you think anyone can give you a confident answer or lead without posted code?
     
  5. IDMah thread starter macrumors 6502

    IDMah

    Joined:
    May 13, 2011
    #5
    Not a leak per-say but when I set up a repeating Timer.

    Code:
    -(void) initMyView
    { 
    myTimer = [NSTimer scheduledTimerWithTimeInterval:(1-(4/12))
    	         target:self 
                     selector:@selector(updateTimer)
    		 repeats:YES];
    //  or //
    [NSTimer scheduledTimerWithTimeInterval:(1-(4/12))
    	         target:self 
                     selector:@selector(updateTimer)
    		 repeats:YES];
    }
    
    it eating more and more memory each 1-(4/12) seconds
    Yes ARC enabled. it seems to be hanging on to the reference. ARC sets myTimer to Strong so it seems to allocate a gazillon of times over and over.

    No matter what I have in updateTimer, even .. memory stills grows.
    Code:
    -(void) updateTimer 
    {
    // nothing 
    // more nothing 
    }
    
    I found this which is basically my issue.
    Memory NSTimer
     
  6. IDMah thread starter macrumors 6502

    IDMah

    Joined:
    May 13, 2011
    #6
    Fix it... with this:

    Code:
     myTimer = [NSTimer scheduledTimerWithTimeInterval:(1-(4/12))
                      target:self 
                      selector:@selector(updateTimer)
                      userInfo:nil
                      repeats:YES];
                 
               NSRunLoop *runner = [NSRunLoop currentRunLoop];
               [runner addTimer:myTimer forMode: NSDefaultRunLoopMode];
    
    
    Works like a charm..
     
  7. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #7
    What number do you expect the expression 1-(4/12) to evaluate to?

    4/12 is a fraction that reduces to 1/3, except you've given it int constants, so the result is an int expression.

    Judging by the rate at which the timer seems to be firing according to the timestamps in the first post, it's firing at thousands of times per second.


    To get a double expression that is 2/3 secs (1 - 1/3), you need a decimal-point in the fractional part, like this:
    Code:
    1 - 1.0/3
    
     

Share This Page