memory - iOS - Object deallocation during execution -


The reference to the developer of the applet reveals that if there is no solid reference to an object, then an object was canceled is. Could it be that if an example called from a weak reference is in the middle of the execution?

For example, consider the snippet below -

  @interface ExampleObject - doSomething; @ And @ interface strong collar @ property example object strong; @end @implementation StrongCaller - initWithExampleInstance: (ExampleObject *) Example {_strong = Example; } - doSomething {.... [strong doSomething]; .... strong = zero; ....} @end @ Infrastructure weak @ property (weak) example object * weak; @end @implementation WeakCaller - initWithExampleInstance: (ExampleObject *) Example {_weak = Example; } - doSomething {.... [Deducting doSomething]; ....} @end  

Now, in the main thread,

  exampleObject * object = [[ExampleObject alloc] init];  

In thread 1,

  [[Strongklmer initWithExampleInstance: object] doSomething];  

In thread 2,

  [[weak initWithExampleInstance: object] doSomething];  

Assuming that the main thread is no longer in the context of the object, what if the strong is set to zero, when [weak doSomething] is being executed? Is the item in this case GC?

Generally this problem occurs during the asynchronous block execution, where to avoid this problem by changing the logic Is impossible for

But if you are certain that you do not want to change the logic then you can use the same solution in your case. You should modify your method like this

  - (zero) doSomething {Your_Class * pointer = self; // Now this local variable holds strong references to self if (pointer! = Zero) {// self is not canceled ... your code here} // Here the indicator will be removed and strong references automatically Will be issued}  

Comments