Do I need to output id in Obj-C?

Example:

MyClass *funkStation = [[MyClass alloc] init]; [funkStation dance]; id tmp = funkStation; ... [funckStation release]; 

I know that after I finish with the funkStation object, I need to release it, but what about id tmp? I think this is not a copy of the original object, but just a pointer to memory space.

+4
source share
3 answers

tmp and funkstation refer to the same object. You only need to release this object once. Submitting the release to funkstation and tmp does the same.

0
source

It is right. You release funkStation but not tmp .

tmp should only be released if you pointed it with a saved pointer or a copy of the original object:

 id tmp = [funkStation retain]; 
+4
source

If you select an object explicitly using alloc, you need to free it. Same thing with copy.

An identifier is a pointer, so when you assign it, it only assigns the value of a pointer, so you do not need to highlight both variables, since they will refer to the same object. If you do, you will definitely get segfault.

0
source

All Articles