Thursday 12 September 2013

is retaining a static array makes a leak on non-arc project?

is retaining a static array makes a leak on non-arc project?

I got a test code below.
(By this example I faced that an interface cannot be statically allocated
without retain.)
By this codeblock I understood what really retain is.
I wantto be sure if this makes a leak and should I release it in somewhere
else. simply I dont wantto reinitialize each time the array. and made it
static.(disadvantage on memory but advantage on speed)
should I release this retained static array somewhere ? is it a safe code
or have I totaly remove static and retain words and just init with
arrayObjects method classically ? so what may you prefer for me ?
+(NSUInteger)getCoordYByX:(int)ax
{
NSUInteger ret_=-1;
static NSArray *coordsX=nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
coordsX=[[NSArray arrayWithObjects:
[NSNumber numberWithInt:50],
[NSNumber numberWithInt:170],
[NSNumber numberWithInt:190],
[NSNumber numberWithInt:210],
[NSNumber numberWithInt:350],
nil]retain];
/*it is more longer. cropped for test purposes*/
});
ret_=[[coordsX objectAtIndex:ax] unsignedIntegerValue];
return ret_;
}

No comments:

Post a Comment