views:

20

answers:

1
-(IBAction) testTemp: (id) sender{
    id tempObj;
    tempObj = otherObject; //the otherObject will be released in dealloc method;
    [tempObj doSomething];
}

As you can see, I use the tempObj for temp use. I won't use it after the user quit this method, should I need to release the tempObj? and why?

A: 

No you do not need to release the tempObj. The reason is because you do not retain it or do any memory management on it. All that tempObj is a pointer to the otherObject and you are just using it as an alias.

In the code is there any reason not to use otherObject directly - if in the real code you do need to use tempObj then there might well be some memory management involved.

Mark