What's the difference between setting an object to nil vs. sending it a release message in dealloc

前端 未结 4 682
我在风中等你
我在风中等你 2020-12-09 13:49

I have Object:

MyClass *obj= [[MyClass alloc] init];

What\'s the difference between:

[obj release]; // Only obj own this ob         


        
4条回答
  •  醉梦人生
    2020-12-09 14:09

    Setting an object nil will create a memory leak(if you are taking ownership by alloc,retain or copy) because we are not having a pointer to that particular memory location.

    so if you want to dealloc an object you have to take out all ownership of an object before making it nil by calling release method.

    [obj release];
    obj=nil;
    

提交回复
热议问题