• 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: Newbie question: setting a NSNumber
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Newbie question: setting a NSNumber


  • Subject: Re: Newbie question: setting a NSNumber
  • From: email@hidden
  • Date: Tue, 21 May 2002 13:45:09 -0700

At 1:12 PM -0700 5/21/02, David Sinclair wrote:
|- (void) setBlah:(NSNumber *)value
|{
| [blah autorelease];
| blah = [value copy];
|}
|
|or
|
|- (void)setBlah:(NSNumber *)value
|{
| [value retain];
| [blah release];
| blah = value;
|}
|
|(Any comments of which is best -- or another variation? I've seen
|several different forms in various places.)
|
|This seems so trivial an operation... but it isn't working. It
|crashes when the autorelease pool is released in the main loop,
|which suggests the retain etc stuff is wrong, but it looks okay to
|me.

Andy Lee wrote:
|Is "blah" initialized in your class's init method? If not, its value
|is not predictable.

Actually, it is quite predictable: it is guaranteed to be zero. From the documentation on "alloc" (in NSObject):

The isa instance variable of the new instance is initialized to a data
structure that describes the class; memory for all other instance
variables is set to 0.

To the original poster: do you know that "setBlah:" is in fact the culprit? If you simply comment out the code in setBlah: (so that it is effectively

- (void) setBlah:(NSNumber *)value
{
}

), does the problem go away? The code does look OK, which is why I wonder if the problem is where you think it is.

Glen Fisher
_______________________________________________
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: setting a NSNumber
      • From: David Sinclair <email@hidden>
References: 
 >Newbie question: setting a NSNumber (From: David Sinclair <email@hidden>)
 >Re: Newbie question: setting a NSNumber (From: Andy Lee <email@hidden>)

  • Prev by Date: Re: Font panel over modal dialog
  • Next by Date: Re: Cocoa File Copy on MacOS X
  • Previous by thread: Re: Newbie question: setting a NSNumber
  • Next by thread: Re: Newbie question: setting a NSNumber
  • Index(es):
    • Date
    • Thread