This is one way to declare a global, immutable array of objects.
This is not a leak in the sense that distribution is not inaccessible memory. To take this example further (read: stupidity), your program could -retain
all of these objects, and you still would not have a leak by the definition of unreachable memory. The array is initialized exactly once and never reassigned, so the original array will always be available to your method, and its elements are always reachable through the array.
However, this is memory that cannot be restored until the program terminates (provided that the method body is entered). So this is really not a design that I would recommend (in fact, I avoid this design).
A better alternative would look more:
+ (NSUInteger)coordYByX:(int)ax { enum { NCoordsX = 5 }; const NSUInteger CoordsX[NCoordsX] = { 50,170,190,210,350 }; assert(ax < NCoordsX && "invalid index");
This requires zero heap allocations, zero static storage, and zero locks;)
source share