objective c - Can I send release to an ivar without alloc/init? -
i have nsstring property:
.h file
@property (nonatomic, retain) nsstring *str; .m file
@synthesize str; what retain count of str without alloc/init? can [str release] in method?
i assuming new concept of memory management, advise have read of apple docs around memory management before continue development.
basic memory management rules
- you own object create.
- you can take ownership of object using retain.
- when no longer need it, must relinquish ownership of object own.
- you must not relinquish ownership of object don't own.
i refer memory management policy in apple docs understanding of memory management
so when have read apple docs understand going on in code, if don't wrong. can not release object don't have ownership of. violates point 4 of basic memory management rules in apple docs. take ownership of object must str = [[nsstring alloc] init]; (this not needed arc) in .m file.
my recommendation though read arc lot better handling memory management yourself. no longer have things such [str release]; once wanted relinquish ownership of object done automatically.
Comments
Post a Comment