• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Detaching a thread to save a file?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: Detaching a thread to save a file?
      • From: Keith Blount <email@hidden>
References: 
 >Re: Detaching a thread to save a file? (From: Keith Blount <email@hidden>)

  • Prev by Date: Re: Detaching a thread to save a file?
  • Next by Date: Re: UIDatePicker in landscape - displaying items moving into position weirdness
  • Previous by thread: Re: Detaching a thread to save a file?
  • Next by thread: Re: Detaching a thread to save a file?
  • Index(es):
    • Date
    • Thread