IOS and Objective-C: most of the processor time is spent in [NSObject release] and [NSObject saved], but the class method does not perform any memory operations

Image processing applications run quickly on a simulator, but on a real device (iPhone 4GS) very slowly .

When starting the application under the "tools" I see the following call tree:

enter image description here

Note that calls in the red circle are reported to require almost all the processor time of the method.

This method 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 someone explain why most of the processor time is spent on [NSObject release] and [NSObject retain] ?

+8
memory-management profiling ios objective-c instruments
source share
2 answers

If he does not know which is better, ARC will save all the arguments to the method and free them when the method exits (see this mailing list in objc email ).

You can avoid this by annotating the +signTested:p1:p2: arguments with __weak or __unsafe_unretained to suit your needs.

+3
source share

Well, maybe a lot of things. As FrozenDevil says it could be related to ARC if you use it. I assume that, most likely, this method is called a different period within a huge cycle. Try passing weak links, but of course you need to be sure that they exist for the whole process. I would also try to optimize the loop that embeds each loop in the autostart pool.

+1
source share

All Articles