Hi,

Lots of classes define static methods that create objects for instance:

Class NSString:
        +(id) stringWithString: (NSString *) string;

or Class NSArray:
        +(id) arrayWithObjects: (id) firstObj, ...;

I am really confused about next situation and memory management of objects created via those methods. Please, explain.
Imagine class with

        NSString *string;

instance variable. I create it and initiate with method above in:
        -(id) init;

of my class. Now, want to use this string in another method sometime later, say in:
        -(void) plug;

Should I retain string in init?
e.g.:

        -(id) init
        {
          // ...
          string = [NSString stringWithString: @"hello"];
          [string retain];
          // ...
        }

        -(void) dealloc
        {
          // ...
          [string dealloc];
          // ...
        }

        -(void) plug
        {
          // ...
          NSLog( "%@", string);
          // ...
        }

Thanks, Samvel.

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to