I have the following dispatch queue my app :

```
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_async(queue, ^  {  

[activeModel freeUpMallocedData];

// UI Updates have to be made on the main thread, so request from GCD.

dispatch_queue_t queue = dispatch_get_main_queue();
dispatch_async(queue, ^  {  

[mainViewController removeTidyUpScreen];
[mainViewController showSceneList]; 
[activeModel release];

});
});

```

The freeUpMallocedData method updates a UI Progress View :

```
- (void) freeUpMallocedData {

// Calculate the percentage increase for each item in the pointerStorageArray as it is released so we can update the Progress Screen.

float arrayCount = [pointerStorageArray count];
float incrementCounter = 1 / arrayCount; // Caculates 1% of pointerStorageArray
float newValue = incrementCounter;
int stepCounter = 0;

NSString * message;

// Now iterate through the pointerStorageArray and free all malloced memory.

for (NSValue * value in pointerStorageArray) {

    stepCounter ++;
    newValue = newValue + incrementCounter;

    message = [NSString stringWithFormat:@"Freeing Up Memory (%d of %d) ...", stepCounter, (int)arrayCount];

    free(value);

    [self tidyUpProgress:message amount:newValue];

}

}

```

The tidyUpProgress method then executes on the main thread.

```
- (void) tidyUpProgress: (NSString *) progressMsg amount: (float) amount {
if (tidyUpMonitorDelegate) {
    tidyUpProgressMsg = progressMsg;
    tidyUpProgressAmount = amount;
    [tidyUpMonitorDelegate performSelectorOnMainThread:@selector(model3DTidyUpProgressUpdate) withObject:nil waitUntilDone:NO];
}
}

- (void) model3DTidyUpProgressUpdate {
progressView.progress = app.activeModel.tidyUpProgressAmount;
loadingStatus.text = app.activeModel.tidyUpProgressMsg;
}

```

The problem is that the app crashes when the freeUpMallocedData method completes. The reason for this is that my initial dispatch queue moves on to request the main queue which then releases activeView. This seems to hijack the thread from the tidyUpMonitorDelegate before it can perform its last update - when it gets the main thread back the activeView has been released and therefore the app crashes as the model3DTidyUpProgresUpdate method is requesting access to variable in a class which has now been dealloced.

Can anyone advise on how to fix this timing issue ?

Thank you in advance.