To give you a definitive answer I’d need to look at this in a lot more detail, and I just don’t have time to do that in the context of DevForums. If you’d like to go down that path, please open a DTS tech support incident.
My best guess right now is that you have autorelease problems. There’s two potential sources for this:
With regards A, you can reasonable expect the run loop to include an autorelease pool inside the run loop. However, adding your own is unlikely to hurt, so it’s worth changing your look to look like this:
while (!self.isFinished) {
@autoreleasepool {
[[NSRunLoop currentRunLoop] runMode:…];
}
}
With regards B, this is a particularly tricky issue. For a while now (OS X 10.7?) every thread has included an autorelease pool at the top of the thread, so you no longer just leak memory if you autorelease something without first setting up a pool. The gotcha relates to dispatch. Dispatch uses a set of worker threads to service its queues, and if a worker thread is busy it never shuts down and thus never releases its autorelease pool. Recently we added a bunch of infrastructure to help with this. Open up
<dispatch/queue.h>
and search for “autorelease” to learn more.
In your case you’re using dispatch directly so you might be able to avoid this problem using an autorelease pool at the top of your block. Like this:
dispatch_async(…, ^{
@autoreleasepool {
…
}
});
My recommendation is that you make both of these changes and see how that affects things.
Share and Enjoy
—
Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware
let myEmail = "eskimo" + "1" + "@apple.com"