Question

I'm trying to debug some ARC code, and it'd be really helpful if i could find out when an object of a certain class is added to the autorelease pool (not when it is actually autoreleased down the track).

Is this possible, eg with a breakpoint? Or by overwriting the 'autorelease' method and putting a breakpoint in it? Any suggestions?

-- edit --

The problem is that i've got an infrequent crash occurring where a custom subclass of UIView is autoreleased on a background thread, which crashes because UIView's cannot be dealloc'd on a background thread. The trace looks like below:

0    libsystem_kernel.dylib  __pthread_kill + 8
1    libsystem_c.dylib   pthread_kill + 54
2    libsystem_c.dylib   abort + 94
3    libc++abi.dylib     abort_message + 46
4    libc++abi.dylib     default_terminate() + 24
5    libobjc.A.dylib     _objc_terminate + 146
6    libc++abi.dylib     safe_handler_caller(void (*)()) + 76
7    libc++abi.dylib     operator delete(void*)
8    libc++abi.dylib     __cxa_throw + 122
9    libobjc.A.dylib     objc_exception_throw + 94
10   CoreFoundation  +[NSException raise:format:]
11   Foundation  -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 90
12   MYAPP   MySuperclass.m line 156 -[MySuperclass dealloc]
13   MYAPP  MyClass.m line 41 -[MyClass dealloc]
14 ...   libobjc.A.dylib     _objc_rootRelease + 36
15   libobjc.A.dylib     objc_release + 38
16   libobjc.A.dylib     (anonymous namespace)::AutoreleasePoolPage::pop(void*) + 224
17   libobjc.A.dylib     _objc_autoreleasePoolPop + 12
18   CoreFoundation  _CFAutoreleasePoolPop + 18
19   libdispatch.dylib   _dispatch_worker_thread2 + 338
20   libsystem_c.dylib   _pthread_wqthread + 294
Was it helpful?

Solution

This might not help with your problem, but I think it answers your original question:

You can add a symbolic breakpoint on [NSObject autorelease] and then set a condition to match your class. If your running on a device $r0 should hold the pointer to the receiving object. You need to do some casting to make the condition work: (BOOL)[(id)$r0 isKindOfClass:[NSArray class]] breaks whenever an NSArray is added to the autoreleasepool. Note that everything will be running very slow as the debugger has to break on every autorelease and check the condition.

Add a symbolic breakpoint

enter image description here

enter image description here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top