Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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:

enter image description here

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]?