ARC, Instruments and retain cycles
ARC, Instruments and retain cycles
- Subject: ARC, Instruments and retain cycles
- From: Roland King <email@hidden>
- Date: Fri, 23 Dec 2011 12:58:50 +0800
Enjoyable 2 hours tracking down a memory leak in my iOS code. It was clearly a retain cycle but it was very hard to find. For interests sake (and so I can google myself later) I had this in a header file, the two lines separated by plenty of others so it wasn't easy to spot
@interface ..
{
...
id<RKArrayViewDataSource> _dataSource;
}
... many lines of properties
@property( readwrite, weak ) id<RKArrayViewDataSource> dataSource;
and unfortunately this property isn't synthesized (where it would have errored on the mismatch between the property, weak, and the ivar, strong) but hand-rolled as it has other work to do in the setter.
OK so I ran it under Instruments, with the leaks profile which runs allocations and leaks. Allocations showed the living object count increasing, checking the retain/release history for each of them they each ended up with exactly one retain left, very much looked like a retain cycle. Leaks however never showed a single leak, that included the 'Cycles and Roots' tab.
Eventually I went through the retain/release history for one of them (457 lines of it), paired stuff off as well as I could and finally dataSource stuck out as an anomaly and I found the bug. Changing it to id<RKArrayViewDataSource> __weak _dataSource fixed the problem.
I did a little googling on ARC, Instruments and retain cycles and found the following under a discussion about ARC
2. improved instruments support for detecting retain cycles (which I won't talk about here because it's technically covered under the wwdc NDA)
Clearly that's from a number of months ago whilst this stuff was under NDA, I would think that is no longer the case.
Does anyone know anything about improved leak detection in instruments especially as it pertains to retain cycles? This one was a classic retain cycle, even though it comprised a number of objects the fact there was one retain holding it all up should have made it very detectable by a leak detector. I ran the app for some time and cycled around to give some time for old memory to be overwritten etc. but it never found any of them, which is rather disappointing. _______________________________________________
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