Reference:
http://macdevcenter.com/pub/a/mac/2001/07/27/cocoa.html?page=3
http://stackoverflow.com/questions/800570/do-i-need-to-explicitly-alloc-my-nsnumber
Convenience constructors
+stringWithCString
+numberWithChar
....etc.
these class methods are called "convenience constructors"
instead of alloc and init a instance explicitly, like below
(NSString *string = [[NSString alloc] initWithCString:"Hello"];)
convenience constructors can be used like,
(NSString *string = [NSString stringWithCString:"Hello"];)
The former case, we shall use release method to release from memory.
while the later case, we don't need to , because objects returned by convenience constructors are assumed to be autoreleased.
沒有留言:
張貼留言