objective c - strange issue with memory management across threads -
From the background thread, I'm jumping back to initializing an object in the main thread (because it uses UIKit ), Which is then reused by the background thread (which waits for initialization), and memory management is not making me doubt.
// Autorelease is called by another BG thread in the pool - (MyObject *) background {MyObject * myObject = zero; [Self-Performance SelectionManThread: @Selector (InitObCact :) with Object: [NSVLue Value Pointer: and MyObject] Waitunitone: Yes]; Return myObject; } - (zero) initObject: (NSValue *) val {MyObject ** objPtr = (MyObject **) [val pointer value]; * ObjPtr = [[MyObject alloc] init]; }
When myObject is used in background mode it will crash with EXC_BAD_ACCESS.
If we do not crash, however, if we keep InitObject:
to:
* objPtr = [[MyObject alloc] init] ]; In the last line of
and backgroundMethod
:
back [myObject autorelease];
Why? I thought that [[foo alloc] init]
pattern has guaranteed one's retention, but it seems that there is a release around the time of the background. Returns it.
Comments
Post a Comment