Why should we release?

后端 未结 2 684
花落未央
花落未央 2021-01-18 16:58

I often see when we release ab object we immediately set it to nil. I know that release and nil both free the old value associated with object but in case of release it leav

2条回答
  •  感情败类
    2021-01-18 17:49

    It's as BJ said setting it to nil won't free up the memory, and in a non-gc collected environment would cause a memory leak. An alternative that'd possibly be valid as well would be

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

提交回复
热议问题