0

My goal is to initialize a large amount of data on a different (non-main) thread, and then refresh a UIProgressView on the main thread corresponding to the large data load's progress. To do this, I use performSelectorInBackground to load the data, and update the progress throughout the way using performSelectorOnMainThread.

I am currently getting a EXE_BAD_ACCESS error from one of the dictionaries that I am initializing, specifically the line where I am setting self.someDictionary = @{...}. self.someDictionary takes on strong and nonatomic properties, and is initialized on the non-main thread.

As a total newbie to multithreading, I am beginning to see that I shouldn't be setting a strong and nonatomic property (however, changing it to atomic still caused the crash). What else am I doing incorrectly to cause the EXE_BAD_ACCESS error, and how do I set a large amount of data to an NSDictionary on a non-main thread and still be able to update the progress on the main thread?

Thanks!

Edit 1:

Code:

//In viewWillAppear, from the main thread
[self performSelectorInBackground:@selector(populateDictionaries) withObject:nil];

//In populateDictionaries method
Dictionary *someDictionary = [[Dictionary alloc] init];

//the methods inside the Dictionary class
- (id) init{
    self = [super init];
    if (self){
        [self makeDictionaries];
    }

    return self;
}
- (void)makeDictionaries{

    self.insiderDictionary = @{ ...} //this line is causing the crash

}
daspianist
  • 5,336
  • 8
  • 50
  • 94

1 Answers1

0

If you want to perform the process in background try Dispatch queue

ref: https://developer.apple.com/library/ios/documentation/General/Conceptual/ConcurrencyProgrammingGuide/OperationQueues/OperationQueues.html

Thank you.

vivek agravat
  • 251
  • 2
  • 10
  • Hi Vivek, thank you for posting. If you have any specific code suggestions, or related SO questions that you could link, it'd be very helpful. While I am aware of GCD and the concept behind using queues, linking the entire document doesn't necessarily help me understand what's causing the error, or what could be done to solve it. – daspianist Mar 22 '16 at 07:38
  • 1
    The solution to overreleased objects are the zombies. When this feature is enabled, a dummy object (a zombie) is kept on the place of every released object, thus allowing to debug objects which were released already. Very easy to enable: - Double click your executable in the “Executables” in XCode Open “Arguments” tab In “Variables to be set in the environment” (that’s the list at the bottom, be careful which one you edit) click the “+” button and for name of the variable enter “NSZombieEnabled” and for value “YES” – vivek agravat Mar 22 '16 at 07:42