Here is my ItemInfo class interface
@interface ItemInfo : NSObject {
NSString *item;
}
@property (nonatomic, copy) NSString *ipaddress;
… and the implementation
@synthesize item;
- (id) initWithItem:(NSString *)someItem {
self = [super init];
if(self) {
item = someItem; // Ideally these things should happen here.
// Since item is a NSString and not NSMutableString,
// it should be sent a retain, thus
// making its refcount = 1
// Is my understanding correct?
}
return self;
}
- (void) dealloc {
[item release]; // I own 'item', so I should release it when done
[super dealloc];
}
I am using this class from elsewhere like thus:
char *str = inet_ntoa(addy->sin_addr);
ItemInfo *h = [[ItemInfo alloc] initWithItem:[NSString stringWithFormat:@"%s", str]];
ContentBrowserViewController *d
= [[ContentBrowserViewController alloc] initWithItemInfo:h];
[self.navigationController pushViewController:d animated:YES];
[h release];
[d release];
The crash I am encountering is
*** -[CFString release]: message sent to deallocated instance 0x6225570. 0x6225570 is the address of h.item
Where am I going wrong?
You need to call your setter using
self.item = someItem. You currently disregard the setter and therefore do not copy/own the String.