• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Memory Management and objects creation via static methods...
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: Memory Management and objects creation via static methods...
      • From: "Sherm Pendley" <email@hidden>
    • Re: Memory Management and objects creation via static methods...
      • From: Jens Alfke <email@hidden>
    • Re: Memory Management and objects creation via static methods...
      • From: Ken Thomases <email@hidden>
  • Prev by Date: outlineViewSelectionDidChange not called
  • Next by Date: Re: Memory Management and objects creation via static methods...
  • Previous by thread: Re: outlineViewSelectionDidChange not called
  • Next by thread: Re: Memory Management and objects creation via static methods...
  • Index(es):
    • Date
    • Thread