Re: Detaching a thread to save a file?
Re: Detaching a thread to save a file?
- Subject: Re: Detaching a thread to save a file?
- From: Graham Cox <email@hidden>
- Date: Sat, 12 Dec 2009 12:52:22 +1100
On 12/12/2009, at 12:37 PM, Keith Blount wrote:
> NSDictionary *searchIndexesDeepCopy = [NSKeyedUnarchiver unarchiveObjectWithData:[NSKeyedArchiver archivedDataWithRootObject:searchIndexes]];
>
> [NSThread detachNewThreadSelector:@selector(saveSearchIndexes:) toTarget:self withObject:searchIndexesDeepCopy];
OK, but 'searchesIndexDeepCopy' (which becomes 'searchInfo') is not used in the thread as written, so why do this?
> - (void)saveSearchIndexes:(NSDictionary *)searchInfo
> {
> [myXMLGeneratedData writeToURL:myUrl atomically:YES];
> }
Where does 'myXMLGeneratedData' and 'myUrl' come from? If they are data members of the document (or whatever) you need to consider whether they could be mutated by the main thread. If you're gettin gthese out of 'searchInfo' in unshown code you should be OK.
If your app uses retain/release (not garbage collection), you also need to put an autorelease pool in there:
- (void)saveSearchIndexes:(NSDictionary *)searchInfo
{
NSAutoreleasePool* pool = [NSAutoreleasePool new];
[myXMLGeneratedData writeToURL:myUrl atomically:YES];
[pool drain];
}
--Graham
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden