Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 11-18-2009, 09:51 AM   #1 (permalink)
Registered Member
 
manicaesar's Avatar
 
Join Date: Feb 2009
Location: Poznań, Poland
Age: 25
Posts: 103
Default UIWebView & blocked Threads issue (possible bug?)

Hi all!

During developing my application, I came across some strange problem with UIWebView. To be sure that the problem is not a side effect of some possible errors made by me elsewhere in the project, I created very simple new project but the problem still exists...

I created New NavigationBased project, and also created very simple class: WebViewController (subclass of UIViewController naturally). In WebViewController class I implemented only one method (of course dealloc still exists there ):

Code:
- (void)loadView {
	[super loadView];
	
	UIWebView *description = [[UIWebView alloc] initWithFrame:CGRectMake(10.0, 100.0, 300.0, 300.0)];
	NSString *descWithHTML = [NSString stringWithFormat:@"<html><body>%@</body></html>", @"Test"];
	[description loadHTMLString:descWithHTML baseURL:nil];
	[self.view addSubview:description];
	[description release];
	
}
Then, in RootViewController, I added following code:

Code:
- (void)viewDidLoad {
	[super viewDidLoad];
	self.title = @"Root";
}

// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 2;
}


// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString *CellIdentifier = @"Cell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }
    
	// Configure the cell.
	cell.textLabel.text = @"Test";
	
    return cell;
}




- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

	 WebViewController *anotherViewController = [[WebViewController alloc] init];
	 [self.navigationController pushViewController:anotherViewController animated:YES];
	 [anotherViewController release];
}
As you see, its very simple, and there shouldn't be any leaks.

If you then launch this application, you are presented UITableView with 2 clickable cells, and after selecting it, WebViewController is presented.

... the problem is, that each time I create new UIWebView, new thread is started and gets blocked waiting for some semaphore infinitely till the application's termination!!!

The debugger says:
Quote:
Thread 5 (thread 12035):
#0 0x31dd6510 in __semwait_signal ()
#1 0x31d782d0 in _pthread_cond_wait ()
#2 0x31d77a94 in pthread_cond_wait ()
#3 0x31bd69a4 in WTF::ThreadCondition::wait ()
#4 0x35dca0ac in WebCore::LocalStorageThread::localStorageThread ()
#5 0x31d705a8 in _pthread_body ()
#6 0x00000000 in ?? ()
(to achieve this, get to the Console, pause application, and then type thread apply all bt)

If I create 6 UIWebViews (by selecting some cell in RootViewController 6 times), I just get 6 blocked, useless threads!!

Does anyone came across this problem also? Is there a solution to this problem? Or is it a bug in UIWebView implementation?

I spend whole day googling for this problem and found nothing strictly connected to this issue...

Thank you in advance for any suggestions.
--
ML
manicaesar is offline   Reply With Quote
Old 12-22-2009, 06:08 AM   #2 (permalink)
Registered Member
 
Join Date: Dec 2009
Location: Stockholm
Age: 26
Posts: 4
Default

Yeah it's a bug. I had the same problem. It turns out that when you release a web view, that thread (cond_wait) keeps running. If you instantiate a new web view without any preexisting web view using that thread, a new thread is born. But any new webviews you create after the first will use the same thread if that first one is still using it. (The thread starts in loadRequest: ) I solved this problem by keeping all webviews in an array that never gets released until the program terminates. You could probably have a dummy webview instead and load a request at program start, keep that dummy in memory, and release all the other webviews normally.
vakio is offline   Reply With Quote
Old 12-22-2009, 06:58 AM   #3 (permalink)
Registered Member
 
manicaesar's Avatar
 
Join Date: Feb 2009
Location: Poznań, Poland
Age: 25
Posts: 103
Default

Quote:
Originally Posted by vakio View Post
Yeah it's a bug. I had the same problem. It turns out that when you release a web view, that thread (cond_wait) keeps running. If you instantiate a new web view without any preexisting web view using that thread, a new thread is born. But any new webviews you create after the first will use the same thread if that first one is still using it. (The thread starts in loadRequest: ) I solved this problem by keeping all webviews in an array that never gets released until the program terminates. You could probably have a dummy webview instead and load a request at program start, keep that dummy in memory, and release all the other webviews normally.
Thank you for your reply! Do you suggest filing a bug to Apple? Or is it actually filed? Do you have any information?
manicaesar is offline   Reply With Quote
Old 12-22-2009, 09:10 AM   #4 (permalink)
Registered Member
 
Join Date: Dec 2009
Location: Stockholm
Age: 26
Posts: 4
Default

I don't know if anyone's filed a bug report but I've filed one. I think the more bug reports, the more they're likely to fix something.
vakio is offline   Reply With Quote
Old 12-22-2009, 09:48 AM   #5 (permalink)
Registered Member
 
manicaesar's Avatar
 
Join Date: Feb 2009
Location: Poznań, Poland
Age: 25
Posts: 103
Default

Quote:
Originally Posted by vakio View Post
I don't know if anyone's filed a bug report but I've filed one. I think the more bug reports, the more they're likely to fix something.
Ok, good to know. Maybe there is a way I can confirm that I also experienced the bug you've filed (sorry if this is a silly question - I have little experience in filing a bugs to Apple)

I also want to confirm, that your solution to the problem - making fake UIWebView at application start works like a charm!

If someone is interested, how to achieve this:

I've modified the code i posted above in such a way:
In AppDelegate .h file, I added a field:
Code:
UIWebView *fakeWebView;
Then in implementation of AppDelegate .m file, I enhanced applicationDidFinishLaunching and dealloc methods:
Code:
- (void)applicationDidFinishLaunching:(UIApplication *)application {    
    
    // Override point for customization after app launch    
	
	[window addSubview:[navigationController view]];
        [window makeKeyAndVisible];
	
	fakeWebView = [[UIWebView alloc] init];
	[fakeWebView loadHTMLString:[NSString stringWithFormat:@"<html><body>%@</body></html>", @"Fake"] baseURL:nil];
}

#pragma mark -
#pragma mark Memory management

- (void)dealloc {
	[navigationController release];
	[window release];
	[fakeWebView release];
	[super dealloc];
}
Many thanks to you, vakio!
__________________
Do you like Age Of War? Have you played 'The Wars' and are not fully satisfied? Try Empires At War - we bet you will love it!


------------------
Full Version
------------------
Lite Version
------------------
YouTube Game Trailer
manicaesar is offline   Reply With Quote
Old 12-22-2009, 10:00 AM   #6 (permalink)
Registered Member
 
Join Date: Dec 2009
Location: Stockholm
Age: 26
Posts: 4
Default

The bug reports are not public. When you file a report only you and apple can see that report. That's why I think you should file another one, so it's more likely to get their attention.

http://bugreport.apple.com/
vakio is offline   Reply With Quote
Old 12-22-2009, 03:37 PM   #7 (permalink)
Registered Member
 
manicaesar's Avatar
 
Join Date: Feb 2009
Location: Poznań, Poland
Age: 25
Posts: 103
Default

Quote:
Originally Posted by vakio View Post
The bug reports are not public. When you file a report only you and apple can see that report. That's why I think you should file another one, so it's more likely to get their attention.

http://bugreport.apple.com/
Ok, I've done so.

Regards,
--
ML
__________________
Do you like Age Of War? Have you played 'The Wars' and are not fully satisfied? Try Empires At War - we bet you will love it!


------------------
Full Version
------------------
Lite Version
------------------
YouTube Game Trailer
manicaesar is offline   Reply With Quote
Reply

Bookmarks

Tags
cond_wait, pthread, semwait, uiwebview

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 266
20 members and 246 guests
ADY, AragornSG, Bertrand21, Dani77, Dattee, Duncan C, fkmtc, HDshot, HemiMG, iDifferent, JasonR, macquitzon216, mer10, prchn4christ, Rudy, sacha1996, sneaky, spiderguy84, Sunny46, theone8one
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,885
Threads: 89,231
Posts: 380,768
Top Poster: BrianSlick (7,129)
Welcome to our newest member, bookesp
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 03:12 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0