• 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
Newbie Question (alloc, init, retain?)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Newbie Question (alloc, init, retain?)


  • Subject: Newbie Question (alloc, init, retain?)
  • From: Rob Cohen <email@hidden>
  • Date: Wed, 28 May 2003 09:10:22 -0400

I've been reading the list for a long time and now I've started something
that has prompted a question.

I had an idea for a very simple app to use as a learning exercise. My app
is a one column table that the user types numbers into and the mean average
is calculated as the user types in new numbers.

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]?

Thanks for any help. The light bulb just hasn't gone on yet.

-R
_______________________________________________
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: Newbie Question (alloc, init, retain?)
      • From: "Jonathan E. Jackel" <email@hidden>
    • Re: Newbie Question (alloc, init, retain?)
      • From: Tom Sutcliffe <email@hidden>
  • Prev by Date: Non-fatal errors in frameworks - how should they be noted? (fwd)
  • Next by Date: Re: Smooth fast scrolling programatically
  • Previous by thread: Non-fatal errors in frameworks - how should they be noted? (fwd)
  • Next by thread: Re: Newbie Question (alloc, init, retain?)
  • Index(es):
    • Date
    • Thread