objective c - iphone memory management strange issue -
objective c - iphone memory management strange issue -
this piece of code had written in xcode
foo * myfoo = [[foo alloc] init] ; [myfoo release] ; [myfoo printmessage] ;
if right, should give runtime error when printmessage function called myfoo gets deallocated time. in xcode , code working , print message getting called, problem due setting on xcode?
regards abhijit
you're invoking undefined behaviour accessing freed memory.
it might crash, might work fine, might result in dancing unicorns spewing forth nose.
to observe memory errors whilst you're developing code, should enable nszombie's, see instructions here:
http://www.cocoadev.com/index.pl?nszombieenabled
update
you might wonder why works - certainly os should throw error when seek access memory isn't valid?
the reason why don't error (and why behaviour undefined) checking memory valid on every access result in performance penalty - ie. code run slower, check shouldn't ever happen.
hence must careful trap these errors during development, never happen end user. nszombies best tool finding them.
one other point - if "build , analyze" in xcode, might find error at build time. static analyzer observe memory errors @ build time.
iphone objective-c nszombie
Comments
Post a Comment