objective c - XCode/Instruments not showing memory leaks -


i'm following stanford ios development lectures , have calculator brain class has been alloc init in controller haven't released in dealloc.

- (calculatorbrain *)brain {     if (!brain)          brain = [[calculatorbrain alloc] init];      return brain;  } 

i ran xcode -> run performance tool , app started , no leaks appeared, clicked home button in ios simulator , nothing, double clicked home button , closed app , still nothing.

i did build & analyse , didnt spot anything

could let me know why not picking up?

it appears if there no detectable leak. @ line:

brain = [[calculatorbrain alloc] init]; 

as long brain points object, object won't considered "memory leak". if @ point this,

brain = nil; 

then leak register. deallocating container object achieve this, sure it's being deallocated? (it won't deallocated when program exits, example.)

the problem: leak detectors cannot detect memory leaks -- mathematically proven fact. detectors detect unreachable objects, , many leak detectors susceptible false negatives -- in c hard tell difference @ runtime between pointer , integer.

edit: sounds application ever creates 1 instance of controller, creates 1 instance of calculatorbrain. if think memory leak is, can define unused memory program not release operating system.

  • while program running, calculatorbrain in use , therefore not leak.
  • when program exits, operating system automatically reclaims memory used process, therefore there cannot memory leaks after program exits.

if want create leak see looks like, create new calculatorbrain multiple times while program running, forget release unused versions. in scenario, program runs, more , more instances of calculatorbrain accumulate. on ios , other embedded systems, crash program. on modern 64 bit computer gradually fill available swap space until run out of swap, address space, or other resource -- causing program crash or making system unresponsive.

standard practice not care deallocating objects supposed exist entire program's run.


Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -