Memory Management and objects creation via static methods...
Memory Management and objects creation via static methods...
- Subject: Memory Management and objects creation via static methods...
- From: Samvel <email@hidden>
- Date: Mon, 24 Mar 2008 23:19:39 -0500
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 (email@hidden)
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:
This email sent to email@hidden