0

I have a question about best practice in downloading data using NSOperation. Currently I am using NSOperationQueue to make multiple requests for JSON data on a remote server. When the data comes in I break it apart into one large NSDictionary and use for loops to parse it out and load the data into NSMutableDictionaries before I go on to the next request. My question is that I am performing this same sequence many times over and over again and I am wondering if it would be a better idea to just download the data and after all the downloads have been completed, then parse out my JSON into the needed Dictionaries, maybe there is a better way to do this that I am just not thinking of? I checked the total allocations using instruments and it looks like the I am pilling up around 30mb during this process.

Would appreciate any kind of advice on this matter.

Here is a small sample of NSOperation Code

          plantPackKeys = [NSMutableDictionary dictionaryWithDictionary:data];
          queueTwo = [NSOperationQueue new];
          [queueTwo setMaxConcurrentOperationCount:4];

          for(id key in data){
             @autoreleasepool {
                urlKey = @"";
                urlKey = [data objectForKey:key];
                DownloadOperation *downLoad = [[DownloadOperation alloc] initWithURL:[NSURL URLWithString:urlKey]];
                [downLoad addObserver:self forKeyPath:@"isFinished" options:NSKeyValueObservingOptionNew context:NULL];
                [queueTwo addOperation:downLoad];
              }
          }
AgnosticDev
  • 1,843
  • 2
  • 20
  • 36

1 Answers1

1

It would be interesting to know which objects are consuming this amount of memory. You could reduce the memory footprint by breaking down the data packages from the server. Another question is do you really need to keep that much data in memory?

You could use some other backend such as CoreData or raw SQLite to save your data to disk as it is parsed. The advantage is that you do not to load everything in memory at once, which is the case with serialized NSDictionaries.

GorillaPatch
  • 5,007
  • 1
  • 39
  • 56
  • Hello GorillaPatch, it looks that a lot of my memory was being pilled up by loops that I was running that could have been thought out a bit more to reduce the number of iterations. I have since cut the memory down to less than a third of what it was. How does CoreData compare to NSDictionaries? Is CoreData a table structure like a database? – AgnosticDev Feb 16 '13 at 14:57