Ok I am working on a very simple example to help me understand objective c @property function. I don't understand why if I run the code I keep getting the _NSAutoreleaseNoPool(): Object 0x2040 of class NSCFString autoreleased with no pool in place - just leaking What does this mean anyway, I am leaking memory because I didn't release it? What wasn't released?
I am not new to C/C++. I implemented my own getter and setter with no problem. If I use the @property to generate code and use anything except @property (assign) NSString *name; then I get this error. This assign is a pointer assignment, while the other two, copy, retain are just similar but increase the count for this object.
Please help, as I have been staring at this for awhile now. I left my code for the setter and getter to ask, is this what the code @property generates? If it does I don't know why it is giving me problems. Looking at main, all I see is that I have set my objects with constant NSStrings. Then I output a object's name by writing it to NSLog. Right when this is called I error.
I am not new to C/C++. I implemented my own getter and setter with no problem. If I use the @property to generate code and use anything except @property (assign) NSString *name; then I get this error. This assign is a pointer assignment, while the other two, copy, retain are just similar but increase the count for this object.
Please help, as I have been staring at this for awhile now. I left my code for the setter and getter to ask, is this what the code @property generates? If it does I don't know why it is giving me problems. Looking at main, all I see is that I have set my objects with constant NSStrings. Then I output a object's name by writing it to NSLog. Right when this is called I error.
Code:
@interface Person : NSObject
{
NSString *name;
}
- (id)init;
@property (retain) NSString *name;
@end
@implementation Person;
-(id)init
{
if(self = [super init])
{
name = @"Bob";
}
return self;
}
@synthesize name;
/*- (NSString *)name
{
return name;
}*/
/*- (void)setName:(NSString *)newName
{
if (name != newName) //
{
[name release];
name = [newName retain];
}
}*/
- (void)dealloc
{
//class cleanup
[name release];
//super cleanup
[super dealloc];
}
@end
int main(int argc, char *argv[])
{
Person *bill = [[Person alloc] init];
Person *bob = [[Person alloc] init];
[bill setName:@"bill"];
[bob setName:@"bob"];
NSLog(bob name];
[bob release];
[bill release];
return NSApplicationMain(argc, (const char **) argv);
}