This sentence in obj1 = [obj2 retain]; points the pointer of obj1 to obj2, so obj1The space that it originally pointed to was no longer taken care of, so it was leaked. obj1 = [obj2 retain];这一句,把obj1的指针指到obj2那块儿去了,所以obj1原来指的那块空间就没人管了,就泄漏了。
So as far as this issue is concerned, obj1 = [obj2 retain]; needs to be preceded by [obj1 release];. As for what it should be in terms of engineering specifications, I don’t know. It's clear, I haven't written much about non-ARC. If it’s not for an interview, try to use ARC. 🎜
This sentence in
obj1 = [obj2 retain];
points the pointer ofobj1
toobj2
, soobj1
The space that it originally pointed to was no longer taken care of, so it was leaked.obj1 = [obj2 retain];
这一句,把obj1
的指针指到obj2
那块儿去了,所以obj1
原来指的那块空间就没人管了,就泄漏了。所以单就这个问题而言是
So as far as this issue is concerned,obj1 = [obj2 retain];
前面就要[obj1 release];
obj1 = [obj2 retain];
needs to be preceded by[obj1 release];
. As for what it should be in terms of engineering specifications, I don’t know. It's clear, I haven't written much about non-ARC. If it’s not for an interview, try to use ARC. 🎜