Re: [solved] How to debug *** -[NSCFString count]: unrecognized selector sent to instance
Re: [solved] How to debug *** -[NSCFString count]: unrecognized selector sent to instance
- Subject: Re: [solved] How to debug *** -[NSCFString count]: unrecognized selector sent to instance
- From: Marc Stibane <email@hidden>
- Date: Sat, 18 Apr 2009 19:19:23 +0200
Am 18.04.2009 um 06:20 schrieb Jeremy W. Sherman:
You might want to couple use of NSZombie with malloc_history. You
can then find out the callstack when the memory was allocated for
your undead object. See its man page to find what environment
variables you must set to have it record info. When you get the
message sent an autoreleased object message, run malloc_history
<your app's pid> <the memory address> and look at the output.
Since the bug doesn't show up when running the simulator with
Instruments, I could as well try it with the device...
(2 hours later) I finally managed to record a crash with Instuments on
the device. From Xcode's organizer console log I got the address of
the zombie object, and in Instruments I could finally see what it is
(CFDictionary, 64 bytes) and who allocated it.
But it isn't my object!
Responsible Library is GraphicsServices, Responsible Caller is
PurpleEventCallback.
Again the callstack:
#0 0x00003a3c in -[ResultViewController limitSegmentPressed:] at
ResultViewController.m:336
#1 0x30a551e9 in -[UIApplication sendAction:to:from:forEvent:]
#2 0x30ab4bce in -[UIControl sendAction:to:forEvent:]
#3 0x30ab5096 in -[UIControl(Internal) _sendActionsForEvents:withEvent:]
#4 0x30ab4c3f in -[UIControl sendActionsForControlEvents:]
#5 0x30ae1511 in -[UISegmentedControl setSelectedSegmentIndex:]
#6 0x30a6d7ab in -[UIWindow sendEvent:]
#7 0x30a5d0ea in -[UIApplication sendEvent:]
#8 0x30a5c50d in _UIApplicationHandleEvent
#9 0x31550396 in SendEvent
#10 0x31552700 in PurpleEventTimerCallBack
#11 0x928f85f5 in CFRunLoopRunSpecific
It seems I found a system bug.
a) user taps on segment
b) UIApplicationHandleEvent allocates a dictionary
(CFDictionaryCreateMutable)
c) [UISegmentedControl setSelectedSegmentIndex:]
...
- it would be interesting to know whether the dictionary is still
alive at this time or already zombied.
d) [ResultViewController limitSegmentPressed:] (my event handler)
e) my code makes a http request with NSURLConnection
- and here the dictionary is zombied when the crash occurs - but still
alive when not
f) my code returns
g) UIApplicationHandleEvent calls [dictionary count]
- crash
When running without zombies enabled, I can "po hexaddr", and usually
it's one of the NSStrings I used to construct the http POST arguments
for my connection. That indicates that the dictionary is already
zombied before my event handler code is called in step d).
So who flushes the autorelease pools?
In order to give the server time to compute the data I waited a bit
before calling NSURLConnection
[[NSRunLoop currentRunLoop] runUntilDate:[now addTimeInterval:
0.05f]]; // wait a bit (1/20 sec)
==> NEVER DO THAT IN AN EVENTHANDLER / IBAction
I did the same with the skip/prev buttons, but the crash didn't happen
there because no autoreleased object was used with UIButtons - only
with UISegmentedControl.
Still I'd say it's a bug in the system not to retain the dictionary
when calling the application's event handler.
--
In a world without walls and fences,
who needs windows and gates?
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden