मैं निम्न उदाहरण वर्ग:उद्देश्य सी NSString * संपत्ति गिनती विषमता को बनाए रखने
Test.h:
@interface Test : UIButton {
NSString *value;
}
- (id)initWithValue:(NSString *)newValue;
@property(copy) NSString *value;
Test.m:
@implementation Test
@synthesize value;
- (id)initWithValue:(NSString *)newValue {
[super init];
NSLog(@"before nil value has retain count of %d", [value retainCount]);
value = nil;
NSLog(@"on nil value has retain count of %d", [value retainCount]);
value = newValue;
NSLog(@"after init value has retain count of %d", [value retainCount]);
return self;
}
निम्नलिखित में से कौन उत्पादन का उत्पादन:
2008-12-31 09:31:41.755 Concentration[18604:20b] before nil value has retain count of 0
2008-12-31 09:31:41.756 Concentration[18604:20b] on nil value has retain count of 0
2008-12-31 09:31:41.757 Concentration[18604:20b] after init value has retain count of 2147483647
मैं कॉल कर रहा हूँ इसे इस तरह से करें:
Test *test = [[Test alloc] initWithValue:@"some text"];
मूल्य 1 की गणना नहीं होना चाहिए? मैं क्या खो रहा हूँ?
आपकी मदद के लिए धन्यवाद।
यह वास्तव में मूल पोस्टर कोड के साथ मौलिक मुद्दों को संबोधित नहीं करता है: वह स्मृति प्रबंधन नियमों का पालन नहीं कर रहा है, और वह संपत्ति के माध्यम से जाने के बजाय सीधे एक आवृत्ति चर निर्दिष्ट कर रहा है। –