I am still enveloping some of the nuances of memory management in objective-C, and came up with the following case, which I'm not sure about:
+ (NSDecimalNumber*)factorial: (NSDecimalNumber *)l { NSDecimalNumber *index = l; NSDecimalNumber *running = [NSDecimalNumber one]; for (; [index intValue] > 1; index = [index decimalNumberBySubtracting:[NSDecimalNumber one]]) { running = [running decimalNumberByMultiplyingBy: index]; } return running; }
Here, decimalNumberByMultiplyingBy and decimalNumberBySubtracting will create a lot of NSDecimalNumbers, which will eventually get auto-implemented, but I'm still worried that the containing program will hang up to a huge amount of memory.
Should I ever introduce a pool of abstracts? (If where is this?) Will this have a noticeable effect on performance (compared to the side effect of using a lot of memory)?
Is autoreleasing the correct mechanism to use here? Should I watch how to break the loop and manually free the memory, how did I do it?
This is probably a n00b question, but I'm trying to get an idea that the best practice is in this situation.
source share