tags:

views:

43

answers:

2

My app will create an object. That object will continuously run one of its method, let's say batch processing pictures.

If its method is running, and I release the object and it is dealloced, will iOs automatically deal with the method of the object? for example, automatically stop running the method of the object and avoiding bad_exec?

+1  A: 

when you call release and your reference count reaches 0 your object's dealloc is called. that's it.

that means: if you're processing on one thread and your object is sent release from another thread (or the same thread for some other bad reason) then you should expect undefined behavior (which will likely result in termination, by EXC_BAD_ACCESS or something equally pleasant). something should hold on to a reference to the object in this case (e.g., an NSOperation subclass).

Justin
A: 

If you release an object, that means the OS is free to reuse the memory and overwrite it with other data.

Thus any reference within that object's method, after final release, to self, an ivar, a getter, a setter, or any other method that requires such (recursively) could crash or, worse, randomly corrupt memory being used elsewhere.

A method that purely uses global or local variables (and not needing further initialization or assignment from the object) might be safe, but that's just a C function or class method masquerading as an instance method.

hotpaw2