Forums
New posts
Articles
Product Reviews
Policies
FAQ
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Menu
Log in
Register
Install the app
Install
Forums
macOS & iOS Developer Playground
macOS - Development and Darwin
Objective C, New to @property
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="C4tSn4cks" data-source="post: 1022166" data-attributes="member: 148326"><p>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?</p><p></p><p>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 (<strong>assign</strong>) 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. </p><p></p><p>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. </p><p></p><p>[CODE]</p><p>@interface Person : NSObject</p><p>{</p><p> NSString *name; </p><p>}</p><p></p><p>- (id)init;</p><p>@property (retain) NSString *name;</p><p>@end</p><p></p><p>@implementation Person;</p><p></p><p>-(id)init</p><p>{</p><p> if(self = [super init])</p><p> {</p><p> </p><p> name = @"Bob";</p><p> </p><p> }</p><p> return self;</p><p>}</p><p></p><p>@synthesize name;</p><p></p><p>/*- (NSString *)name</p><p>{</p><p> return name;</p><p>}*/</p><p></p><p>/*- (void)setName:(NSString *)newName </p><p>{ </p><p></p><p>if (name != newName) //</p><p> { </p><p> [name release]; </p><p> name = [newName retain]; </p><p></p><p> } </p><p>}*/</p><p></p><p></p><p>- (void)dealloc</p><p>{</p><p> //class cleanup</p><p> [name release];</p><p> //super cleanup</p><p> [super dealloc];</p><p>}</p><p></p><p></p><p>@end</p><p></p><p>int main(int argc, char *argv[])</p><p>{</p><p> Person *bill = [[Person alloc] init];</p><p> Person *bob = [[Person alloc] init];</p><p> </p><p> [bill setName:@"bill"];</p><p> [bob setName:@"bob"];</p><p></p><p> NSLog(bob name];</p><p></p><p> [bob release]; </p><p> [bill release];</p><p> return NSApplicationMain(argc, (const char **) argv);</p><p>}</p><p></p><p>[/CODE]</p></blockquote><p></p>
[QUOTE="C4tSn4cks, post: 1022166, member: 148326"] 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 ([B]assign[/B]) 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); } [/CODE] [/QUOTE]
Verification
How many occurrences of a n-u-m-b-e-r between "d" and "f" in this example...(sdgs6ngklu3gd#f9%)?
Post reply
Forums
macOS & iOS Developer Playground
macOS - Development and Darwin
Objective C, New to @property
Top