Hi all,
after having spent few months in trying to master the syntax and rules, I am going deeper in memory management rules. One thing I do not understand and causing me confusion is how one creates objects.
Based on what stated in apple memory management guide, the following is a valid approach:
– (NSArray *)sprockets {
NSArray *array = [NSArray arrayWithObjects:mainSprocket,auxiliarySprocket, nil];
return array;
}
because I am not causing any memory leaks. The reason why is that it's not using alloc for creating array and therefore sprockets is not the owner. However I am wondering now what's inside arrayWithObjects. Because it happens that in my apps I often have factory for creating custom objects using something similiar to:
return [[MyObject alloc] initWithParameter:(id)params]; // possible leak
If I want to change with a static method like:
return [MyObject initWithParameter:(id)params];
what could be in initWithParameter for adhere to memory rules ? And what if MyObject extends some other object ? I also find out that method naming rules are important to properly advise programmer, what are this rule ? Also could you point out a web link where this is explained (I am not yet good in finding docs on apple web site).
thanks