Reputation:
I have a following code:
NSLog(@"%d", [chart retainCount]);
self.chart = [[BNPieChart alloc] initWithFrame:self.view.frame];
NSLog(@"%d", [chart retainCount]);
Terminal shows:
[Session started at 2011-03-28 11:09:46 +0200.]
2011-03-28 11:09:51.008 Finance[35111:207] 0
2011-03-28 11:09:51.010 Finance[35111:207] 2
As I know, retainCount should be equal to 1, not 2.
Upvotes: 3
Views: 1149
Reputation: 115
There are 3 possible problems I see:
chart
property, it was synthesized with a retain
attributeretain
in a self-implemented getter methodBNPieChart
or its superclass's designated initializer had a retain
in the initializer.Have you seen the code for BNPieChart
and its non-Cocoa superclasses? If you can, try to post the initializer code.
Upvotes: 0
Reputation: 6139
You chart property defined as retain or copy, so:
self.chart = [[BNPieChart alloc] initWithFrame:self.view.frame];
+1 retain at alloc ([BNPieChart alloc]
)
+1 retain at assignment (self.chart =
)
Upvotes: 6
Reputation: 8735
chart is probably a retained property, that's why you have 2 retainCount. That's why you can see some declaration like that :
BNPieChart *aChart = [[BNPieChart alloc] initWithFrame:self.view.frame];
self.chart = aChart;
[aChart release];
Upvotes: 3
Reputation: 13843
Due to self in the statement its retain count is 2 as property of the chart is declared as retain
Remove self from the statement
change
self.chart = [[BNPieChart alloc] initWithFrame:self.view.frame];
to
chart = [[BNPieChart alloc] initWithFrame:self.view.frame];
Upvotes: 1
Reputation: 9198
How do you know that the retainCount should be 1? Are you the author of the -setChart: method you are calling? How is it implemented? Why didn't you include it in the post?
Nothing you have posted here is suspicious.
Upvotes: 0