Re: Newbie question: setting a NSNumber
Re: Newbie question: setting a NSNumber
- Subject: Re: Newbie question: setting a NSNumber
- From: Ondra Cada <email@hidden>
- Date: Tue, 21 May 2002 22:37:35 +0200
On Tuesday, May 21, 2002, at 10:24 , Andy Lee 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.
And to me, too.
You can try to use -retainCount to track the moment where things go wrong.
.. alas, at the moment I can't give a better advice :(((.
Is "blah" initialized in your class's init method? If not, its value is
not predictable.
Presumed it is a property, its value *IS* a very predictable zero.
If it happens to be zero (nil), then you won't notice the bug, but if it
points to a bogus memory address, the attempt to release it will crash
your program.
Nope. Non-nilling a property is not a bug and won't crash anything, since
objects are zeroed when allocated.
---
Ondra Cada
OCSoftware: email@hidden
http://www.ocs.cz
2K Development: email@hidden
http://www.2kdevelopment.cz
private email@hidden
http://www.ocs.cz/oc
_______________________________________________
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.