iphone - Why is object not dealloc'ed when using ARC + NSZombieEnabled -



iphone - Why is object not dealloc'ed when using ARC + NSZombieEnabled -

i converted app arc , noticed object alloc'ed in 1 of view controllers not beingness dealloc'ed when view controller dealloc'ed. took while figure out why. have enable zombie objects on project while debugging , turned out cause. consider next app logic:

1) users invokes action in rootviewcontroller causes secondaryviewcontroller created , presented via presentmodalviewcontroller:animated.

2) secondaryviewcontroller contains actionscontroller nsobject subclass.

3) actionscontroller observes notification via nsnotificationcenter when initialized , stops observing when dealloc'ed.

4) user dismisses secondaryviewcontroller homecoming rootviewcontroller.

with enable zombie objects turned off, above works fine, objects deallocated. enable zombie objects on actionscontroller not deallocated though secondaryviewcontroller deallocated.

this caused problems in app b/c nsnotificationcenter continues send notifications actionscontroller , resulting handlers cause app crash.

i created simple app illustrating @ https://github.com/xjones/xjarctestapp. @ console log enable zombie objects on/off verify this.

question(s)

is right behavior of enable zombie objects? how should implement type of logic eliminate issue. go on using enable zombie objects.

edit #1: per kevin's suggestion i've submitted apple , openradar @ http://openradar.appspot.com/10537635.

edit #2: clarification on answer

first, i'm experienced ios developer , understand arc, zombie objects, etc. if i'm missing something, of course, appreciate illumination.

second, true workaround specific crash remove actionscontroller observer when secondaryviewcontroller deallocated. have found if explicitly set actionscontroller = nil when secondaryviewcontroller dealloc'ed dealloc'ed. both of these not great workaround b/c require utilize arc code if not using arc (e.g. nil ivars explicitly in dealloc). specific solution doesn't help identify when issue in other controllers developers know deterministically when/how workaround issue.

a reply explain how deterministically know need special wrt object when using arc + nszombieenabled solve specific illustration , apply project whole w/o leaving potential other similar problems.

it exclusively possible reply doesn't exist may bug in xcode.

thanks all!

turns out, i've written serious nonsense

if zombies worked wrote, turning on zombies straight lead innumerable false positives...

there isa-swizzling going on, in _objc_rootrelease, override of dealloc should still called zombies enabled. thing won't happen zombies actual phone call object_dispose — @ to the lowest degree not default.

what's funny that, if little logging, see arc enabled, implementation of dealloc phone call through it's superclass's implementation.

i assuming not see @ all: since arc generates these funky .cxx_destruct methods dispose of __strong ivars of class, expecting see this method phone call dealloc — if it's implemented.

apparently, setting nszombieenabled yes causes .cxx_destruct not called @ — @ to the lowest degree that's happened when i've edited sample project: zombies off leads backtrace , both deallocs, while zombies on yields no backtrace , 1 dealloc.

if you're interested, additional logging contained in a fork of sample project — works running: there 2 shared schemes zombies on/off.

original (nonsensical) answer:

this not bug, feature.

and has nil arc.

nszombieenabled swizzles dealloc implementation which, in turn, isa-swizzles object's type _nszombie — dummy class blows up, send message it. expected behavior , — if i'm not exclusively mistaken — documented.

iphone ios automatic-ref-counting nszombieenabled

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -