I have 2 variables:
UIView *view1;UIView *view2 = [[UIView alloc] init]
When I assign view1=view2 – should I release view2? Or just release view1?
Or view1 = [view2 retain]; [view1 release]; is right way?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It totally depends on what
view1andview2are at the time of yourview1 = view2. If it’s like this:Then it’s totally fine to just do:
If however
view1already points to an object such as in this:Then you would want to (probably) do this:
I say probably because, well, it depends on what you are wanting to do. Maybe you don’t want the
retainonview2because you might not want to have a strong reference to it.Of course all this is moot if you just use ARC anyway :-D.