Re: Newbie Question (alloc, init, retain?)
Re: Newbie Question (alloc, init, retain?)
- Subject: Re: Newbie Question (alloc, init, retain?)
- From: John Nairn <email@hidden>
- Date: Wed, 28 May 2003 15:37:51 -0600
See Cocoa documentation or books on memory management, but very briefly
1. If you retain (or create with init method), you have to release it
when done.
2. When you add to another object (built-in class or well-written class
you create), it will retain it if needed and release it when it is done
with it.
Thus, you do not need to create with init and do not need to retain. No
good class should need for you to do that and certainly your Numbers
NSMutableArray does not.
On Wednesday, May 28, 2003, at 07:41 AM,
email@hidden wrote:
>
My question is about memory management and object allocation and
>
initialization. When a number gets added, I add an NSNumber set to
>
0.0 to
>
an NSMutuableArray, something like this:
>
>
NSNumber *foo;
>
foo = [NSNumber numberWithFloat:0.0];
>
[Numbers insertObject:foo atIndex:[Numbers count]];
>
[theTableView reloadData];
>
>
Do I have to send [[foo alloc] init]? How do I know which classes
>
need this
>
message?
>
>
Also since I just add the object to the array, do I need to send [foo
>
retain]?
>
------------
John Nairn (1-801-581-3413, FAX: 1-801-581-4816)
Web page:
http://www.mse.utah.edu/~nairn
_______________________________________________
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.