Destroy object on background thread Objective C
I have an absolutely huge array (~ 10 million objects that contain essential data themselves). The destruction of this object leads to a rather long lag of the main thread of about 5 seconds. While this is just a test case for huge data, I would like to be able to: A) improve its destruction time, or B) push it to some kind of background thread to die. I don't know much about the runtime requirements for a memory collection, but would like the best solution to just spin for 5 seconds.
So the question is how to destroy VERY large objects without bumping into a long destructor waiting for the main thread. I am using ARC and the destructor is called in a reasonable amount of time (set to nil). Has anyone else done this? Is there any design principle or any other strategy for such situations.
Here is what I am looking at while profiling
source to share
I managed to get everything to work and release on a background thread something like:
__block MyHugeObject* lastResults = self.localHugeObject; //retain it for the block
self.localHugeObject = nil;//clear local copy
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
lastResults = nil;//release on a background thread
});
source to share