0

When I Product > Analyze the clang analyzer gives me a memory leak I do not understand. It says that I am leaking in the second line something what was initialized in the first line of the following code

[[testView newScore] setText: [NSString stringWithFormat: @"+%d", addScore]];
[[testView newScore] setTextColor: [UIColor greenColor]];

As Instruments isn't working right now (I am using Xcode 4.1 with SDK 4.3) I can't investigate this leak any further.

Do you see why this could be a memory leak. The property newScore is defined like this:

@property (nonatomic, retain) UILabel *newScore;

and testView is a subclass of UIView.

Edit: Screenshot of the analyzer output: enter image description here

Thank you for reading!

dasdom
  • 13,975
  • 2
  • 47
  • 58

1 Answers1

5

Can you post a screenshot of the analyzer output (i.e. the blue arrows pointing to the problematic control flow)?


Derp; I missed the obvious. Sorry. The method is named newScore and the new* prefix indicates to the compiler that the object returned is +1 retain count.

Rename the method and all will be well.

bbum
  • 162,346
  • 23
  • 271
  • 359