1

Dear Community. I like to understand a little task, which have to help me improve performance for my application. I have array of dictionaries, in singleton area with objects NSDictionary and keys code country specific

I have to receive country and specific values from this array. My first version of application was using predicate, but later i find a lot of memory leaks and performance issues by this way. Application was too slow and don't empty very quickly a memory stack, coming to around 1G and crash.

My second version was little bit more complicated. I was filled array in singleton area with objects per one code and function, which u can see bellow.

-(void)codeIsSame:(NSArray *)codeForCheck;
{
//@synchronized(self) {
NSString *code = [codeForCheck objectAtIndex:0];

if ([_code isEqualToString:code]) 
{
    code = nil;
    NSUInteger queneNumberInt = [[codeForCheck objectAtIndex:1] intValue];
    NSLog(@"We match code:%@ country:%@ specific:%@ quene:%lu",_code, _country,_specific, queneNumberInt);
    [[ProjectArrays sharedProjectArrays].arrayDictionaryesForCountryCodesResult insertObject:_result atIndex:queneNumberInt];
}

code = nil;
//}
return;
}

The way to receive necessary issues is a :

SEL selector = @selector(codeIsSame:);
[[ProjectArrays sharedProjectArrays].myCountrySpecificCodeListWithClass makeObjectsPerformSelector:selector withObject:codePlusQueueNumber];

This version working much better, no memory leaks, very quickly, but too hard to debug. Sometimes i receive empty result, i tried to synchronize thread jobs, but it still not work stable. The main problem in this way is that in strange reason sometimes i don't have result in my singleton array. I tried to debug it, using index of array for different threads, and have result that class just missed answer.

Core data don't allow me to make copy of main MOC and for multithreading design i can't using it (lock and unlock is not good idea, and that's way product too much error in lock/unlock part of code.

Maybe anybody can suggest, what i can do better in this case? I need a best way to make decision which will work stable, will be easy to coding and understand it?

My current solution is using NSDictionary, where is a keys is a code and under that code i have dictionary with country/specific. Working fine as well, but don't decide a main task - using core data if u need multiply access from too many threads to the same data.

Alex
  • 393
  • 6
  • 21
  • Wow - i think this topic is bigger then to be able to explain it in writing ... but ... let's hope for the best :) .. I would suggest reading a design patterns book, but i know this doesn't answer your question ... – Moszi Jan 05 '11 at 20:14
  • Yep :) i'm anyway find solution by the experiment way, but probably guru's try to share their knowledge :) A core data can't working with multithread in case u r using auto arrange array controller. This is a important part, which i have right now and this is change my design application. – Alex Jan 05 '11 at 23:01

0 Answers0