objective c - Does detachNewThreadSelector work any different than NSThread performSelectorInBackground or NSThread alloc/init then [thread start] -
does detachnewthreadselector work different performselectorinbackground? in project use lot of this:
[self performselectorinbackground:@selector(startimagedownloads:) withobject:[nsnumber numberwithint:datatype]]; but doing different:
[nsthread detachnewthreadselector:@selector(startimagedownloads:) totarget:self withobject:[nsnumber numberwithint:datatype]]; and also, besides being able access thread object imgdlthread, alloc/init'ing thread starting work different first 2:
nsthread *imgdlthread = [[nsthread alloc] initwithtarget:self selector:@selector(startimagedownloads:) object:[nsnumber numberwithint:datatype]]; [imgdlthread start]; thanks!
edit:
just realized there's several answers on difference (or lack of) between performselectorinbackground , detachnewthreadselector, guess question is:
is allocating , initializing nsthread calling [thread start] different first 2?
the difference between third method , first 2 memory management. when allocate thread, retains it's target, released when thread deallocated. detatchnewthreadselector: , performselectorinbackground: method both autorelease resulting nsthread created, meaning that, once thread finishes execution, target released.
in code provided (allocate thread , start it), leaking imgdlthread, meaning target never released, , in turn leaked itself. if autorelease or regular release imgdlthread after starting it, have exact same effect detachnewthreadselector:.
Comments
Post a Comment