Results 1 to 3 of 3
  1. #1


    Member Since
    Mar 22, 2010
    Posts
    2
    Objective C, New to @property
    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.

    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);
    }

  2. #2

    Raz0rEdge's Avatar
    Member Since
    Jul 17, 2009
    Location
    MA
    Posts
    8,538
    Specs:
    27" i7 iMac, 24" iMac, 13" Macbook Air, iPhone 6S, iPod Nano 7th GeniPad 3
    In your main function, you need to create a AutoReleasePool and release it at the end of the function..so add
    Code:
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    as the first variable and then before you leave the function, add
    Code:
    [pool release]
    Check out Objective-C Beginner's Guide..

    Regards

  3. #3


    Member Since
    Mar 22, 2010
    Posts
    2
    Hey, I just wanted to say thanks. I added those two lines of code and it worked. I have seen your link before on Objective C, but I overlooked it. I am working off the Standford slides that are posted on itunes. I haven't paid for the iphone SDK yet so their might be differences, although in the link you gave me it says
    When developing Mac Cocoa applications, the auto release pool is setup automatically for you.
    That is a little strange, yes I have #import <Cocoa/Cocoa.h> in my main. Hey, it works for now and that is what is important.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. 2 Houses - 1 Property - Need to Share Internet
    By mrschmitt in forum Internet, Networking, and Wireless
    Replies: 5
    Last Post: 05-08-2012, 10:26 PM
  2. correct property initializing
    By sam256 in forum iOS Development
    Replies: 2
    Last Post: 10-12-2011, 06:38 AM
  3. Replies: 45
    Last Post: 11-22-2009, 03:17 PM
  4. rental property software
    By mdavis71 in forum OS X - Apps and Games
    Replies: 3
    Last Post: 11-14-2005, 10:31 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •