Not OF related; Objective-C constructor question

I’ve been working on something all evening and night, which I’m pleased to say has finally found (some degree of) success, but not until after two hours of puzzling over this:

  
NSNumber* myNum = [NSNumber numberWithFloat: 1.5];  

The above code appears to work, but when I run a loop containing it, the application locks up and sends me back to the debugger.

  
NSNumber* myNum = [[NSNumber alloc] initWithFloat: 1.5];  

This code, on the other hand, causes no problems whatsoever. I assume that +numberWithFloat allocs, so IDGI.

This has only just occurred to me: in the first example am I supposed to init the retrieved value too? i.e.

  
NSNumber* myNum = [[NSNumber numberWithFloat: 1.5] init];  

But then what’s the point of +numberWithFloat if the alternative will do the same thing in less characters?

Maybe I’m just being really thick here

I’d suggest you have a read of this
http://memo.tv/memory-management-with-o-…-coa-iphone
:wink:

especially the bits about object ownership, messages and convenience methods,

Makes perfect sense so it does. Now I just need to figure out how to rotate images — shouldn’t take too long — then I have a demo game already working :o