Note that there are some explanatory texts on larger screens.

plurals
  1. PONSOperationQueue and UITableView release is crashing my app
    primarykey
    data
    text
    <p>This is by far the weirdest problem I've been stuck with.</p> <p>I have a UIViewController on a UINavigationController and I want to call a method at viewDidAppear using NSInvocationOperation so it can run on a back thread when the view becomes visible. </p> <p>The problem is that if I pop the view controller <em>BEFORE</em> the operation (in this case the <em>testMethod</em> method) completes running, the app crashes. </p> <p>Everything works fine if I pop the view controller <em>AFTER</em> the operation runs it's course. </p> <p>When the app crashes, it stops at [super dealloc] with "EXC-BAD-ACCESS" and gives me the following error.</p> <blockquote> <p>bool _WebTryThreadLock(bool), xxxxxxxxx: Tried to obtain the web lock from a thread other than the main thread or the web thread. This may be a result of calling to UIKit from a secondary thread. Crashing now...</p> </blockquote> <p>And this is my code (super simplified)..</p> <pre><code>- (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; NSInvocationOperation *theOperation = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(testMethod) object:nil]; [operationQueue addOperation:theOperation]; [theOperation release]; } - (void)testMethod { NSLog(@"do some stuff that takes a few seconds to complete"); } - (void)dealloc { [_tableView release]; [super dealloc]; } </code></pre> <p>The <em>testMethod</em> has some code that takes a few seconds to complete. I only have a few clues and I really don't know how and where to start debugging this.</p> <ul> <li><p>Clue #1: The funniest thing is that if I remove the [_tableView release]; from dealloc then the app doesn't crash. But of course this would cause a leak and I can't remove it.</p></li> <li><p>Clue #2: I've tested this code on a separate "clean" UIViewController with a UITableView and to my surprise it <em>didn't</em> crash.</p></li> <li><p>Clue #3: The app doesn't crash is the UITableView's datasource is set to nil in viewDidLoad.</p></li> <li><p>Clue #4: The app doesn't seem crash if I use the same code in viewDidAppear somewhere else like an IBAction.</p></li> <li><p>Clue #5: I've tried looking over stack data with NSZombie but it gives me tons of data and it leads me nowhere.</p></li> </ul> <p>I have some very complicated code within my UITableViewDelegate and UITableViewDataSource and I really don't know where to start debugging this. I really hope I don't have to go through line by line or rewrite the entire thing because of this.</p> <p>Any pointers on where I should be looking?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload