All UIWebViews share a single web thread.
When one of them is init
-ed, removed from superview etc., they will attempt to lock the web thread from the main thread in a blocking fashion, thus temporarily freezing the run loop of the main thread.
If the web thread is busy, e.g. while doing a long synchronous XMLHttpRequest
, this may block the main thread for a long time.
Is there a way to avoid this?
If I could modify UIWebView, I'd just make the lock attempt non-blocking, but obviously that's not the case, so I'm looking for other clever ideas.
The long and short of it is: avoid doing anything that blocks the web thread for a significant amount of time (
window.alert
,window.prompt
,XMLHttpRequest.open('GET', url, false)
, possibly others)Also, avoid calling methods that lock the web thread and then immediately doing something that takes a long time as the web thread is only unlocked once control is returned to the run loop. (Example: call
-[UITextView setText:]
then read a file synchronously on the main thread)you cannot make synchronous xhr since this will lead to crossdomain policy errors.