ios - MCSession takes a long time to dealloc -


i'm using multipeer-connectivity.

when session ends, app comes main menu , network stuff released deallocated.

but dealloc method called in main thread , mcsession object takes long time release itself, don't know why, , consequently main menu screen freezes.

if know why mcsession long, i'm interested. if comes mcsession itself, solution this?

-(void) dealloc {     //... other release      dispatch_async(dispatch_get_global_queue(dispatch_queue_priority_default, 0), ^{         [_session release];         _session = nil;     });      [super dealloc]; } 

edit: nope, it's not solution, because makes app crashing. anyway, other ideas?

when call [_session release] since _session ivar, compiler replace line [self->_session release] , block retain self instead of ivar _session. here have 2 problems:

  1. trying retain object(self) deallocating.

  2. when queue executed, it'll call self deallocated.

the following solution create local variable point same address ivar , release inside block, block not capture self.

-(void) dealloc {     //... other release     mcsession* localsession = _session;     dispatch_async(dispatch_get_global_queue(dispatch_queue_priority_default, 0), ^{         [localsession release];     });      [super dealloc]; } 

Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -