iOS and Objective-C: most of CPU time is spent in [NSObject release] and [NSObject retain] but class method is not doing any memory operations
instruments, ios, memory-management, objective-c, profiling
Solution
If it doesn't know any better ARC will retain all the arguments to a method and release them when the method exits (see this objc-language mailing list email).
You should be able to avoid this by annotating the arguments to `+signTested:p1:p2:` with either `__weak` or `__unsafe_unretained`, per your needs.
Problem
An image processing applications runs fast on the simulator, but is really slow on a real device (iPhone 4GS). When running the application under "instruments", I see the following call tree: Note that the calls within the red circle are reported to take almost all of the CPU time of the method. The method in question is a class method (not an instance method), with the following code: ``` @implementation Line2F + (CGFloat)signTested:(Point2F *)tested p1:(Point2F *)p1 p2:(Point2F *)p2 { return [Line2F signTestedX:tested.x testedY:tested.y p1x:p1.x p1y:p1.y p2x:p2.x p2y:p2.y]; } + (CGFloat)signTestedX:(CGFloat)testedX testedY:(CGFloat)testedY p1x:(CGFloat)p1x p1y:(CGFloat)p1y p2x:(CGFloat)p2x p2y:(CGFloat)p2y { return (testedX - p2x) * (p1y - p2y) - (p1x - p2x) * (testedY - p2y); } @end ``` Can anyone explain why is most of the CPU time is spent on `[NSObject release]` and `[NSObject retain]`?