• 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: NSXMLParser in background thread crashing
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSXMLParser in background thread crashing


  • Subject: Re: NSXMLParser in background thread crashing
  • From: "Justin R. Miller" <email@hidden>
  • Date: Fri, 23 Feb 2007 07:56:01 -0500

On Feb 23, 2007, at 12:16 AM, Philip Q wrote:

This isn't what thread safety means -- a thread safe class can be used
from multiple threads without using locks. Large parts of
Foundation/AppKit aren't thread safe, but are safe for using within a
single thread.

Ok, this is good to know. Do you know where I can find more info about this, specifically about defining the boundaries of these 'large parts'? :-)


There shouldn't be any problem with using an NSXMLParser in a separate
thread. What is a bit suspicious, is the NSAutoreleaePool being added
to -parse. Why is it being added?

When I originally ran -parse in a background thread, I got complaints of not having an autorelease pool and that memory was just leaking. So I subclassed NSXMLParser to override just the -parse method and these went away, per this:


Autorelease pools are automatically created and destroyed in the main thread of applications based on the Application Kit, so your code normally does not have to deal with them there. If you are making Cocoa calls outside of the Application Kit's main thread, however, you need to create your own autorelease pool. This is the case if you are a Foundation-only application or if you detach a thread.

http://developer.apple.com/documentation/Cocoa/Conceptual/MemoryMgmt/ Concepts/AutoreleasePools.html#//apple_ref/doc/uid/20000047-1041876- CJBFEIEG


The only code that I am calling in the new thread is the -parse method, so subclassing seemed the best way to accomplish this. I suppose I could also create a custom method on the calling object which creates a pool, calls -parse, releases the pool, and returns, ending the thread, but it seemed unnecessarily complex when subclassing was quite simple.

--
Justin R. Miller
Code Sorcery Workshop
http://codesorcery.net


_______________________________________________

Cocoa-dev mailing list (email@hidden)

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: NSXMLParser in background thread crashing
      • From: Sherm Pendley <email@hidden>
    • Re: NSXMLParser in background thread crashing
      • From: "Philip Q" <email@hidden>
References: 
 >NSXMLParser in background thread crashing (From: "Justin R. Miller" <email@hidden>)
 >Re: NSXMLParser in background thread crashing (From: Jim Correia <email@hidden>)
 >Re: NSXMLParser in background thread crashing (From: "Philip Q" <email@hidden>)

  • Prev by Date: Disabling Menu Items.
  • Next by Date: Re: must change control of NSTokenField selection
  • Previous by thread: Re: NSXMLParser in background thread crashing
  • Next by thread: Re: NSXMLParser in background thread crashing
  • Index(es):
    • Date
    • Thread