• 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
Re: NSMutableArray morphs itself into an NSArray?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSMutableArray morphs itself into an NSArray?


  • Subject: Re: NSMutableArray morphs itself into an NSArray?
  • From: Dustin Voss <email@hidden>
  • Date: Mon, 8 Mar 2004 10:37:16 -0800

On 8 Mar, 2004, at 6:30 AM, Jerry Krinock wrote:

In my application, in a subclassed NSWindowController, I declare the
following member object:

NSMutableArray* crontabLines;

During my subclassed -initWindowWithNibName, I alloc/init it:

crontabLines = [NSMutableArray array] ;
[crontabLines retain] ;

Later, in a member method, I use it to temporarily store several NSString*s,
and then retain it.

I don't know why you can't remove objects, but if you are retaining crontabLines several times, I do think you are mis-managing memory.

The convenience constructors like +array are intended for local variables, not instance variables. To allocate an instance variable, the pattern is:

crontabLines = [[NSMutableArray alloc] init];

If you use +array then the mutable array will be put in the auto-release pool. It won't get auto-released -- because you retain it -- but there is no need for it to go in the auto-release pool at all.

Further, once you have created the array in your -initWindowWithNibName: method, there is no reason to retain it again in another method of the same class.

Retain is used to keep an object around when it might otherwise be deallocated. Within your window controller, you don't need to worry about sudden deallocation, because you had guaranteed a reference count of at least one in your -initWindowWithNibName: method. You will only remove that guarantee in your -dealloc method, when you call [crontabLines release].

You may want to reread the material on memory management at <http://developer.apple.com/documentation/Cocoa/Conceptual/MemoryMgmt/ index.html>.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.


  • Follow-Ups:
    • Re: NSMutableArray morphs itself into an NSArray?
      • From: Shawn Erickson <email@hidden>
    • RE: NSMutableArray morphs itself into an NSArray?
      • From: "Jonathan E. Jackel" <email@hidden>
References: 
 >NSMutableArray morphs itself into an NSArray? (From: Jerry Krinock <email@hidden>)

  • Prev by Date: Re: A possible vImage bug ?
  • Next by Date: Calling tableView:setObjectValue directly...
  • Previous by thread: NSMutableArray morphs itself into an NSArray?
  • Next by thread: RE: NSMutableArray morphs itself into an NSArray?
  • Index(es):
    • Date
    • Thread