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:
trying retain object(self) deallocating.
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
Post a Comment