At the moment, in the code you specified, getNewDatabase: running in the main thread of your application. The problem in this particular case is then something other than the life cycle of the thread, as James noted in his case.
If you intended to perform this operation in the background, I would recommend using NSOperationQueue and NSOperation instead of solving the problem with the current code. I think your case is great for NSOperationQueue , especially if you have several loading tasks.
Dave Dribin has an excellent article on using an asynchronous API, such as NSURLConnection, inside NSOperation . Alternatively, if you are working in a background thread, you can also simplify this process and simply use the synchronous API method instead of your NSOperation, for example initWithContentsOfURL:
Marcus Zarra also wrote a tutorial that demonstrates how easy it is to enable and use NSOperationQueue for simple background operations.
source share