1

i'm working on app for iphone on objective-c i have array with object references If i remove item with object reference from array should i release this object additionally or it will be removed from memory automatically?

3 Answers 3

2

When removed from array object gets released once. So if your retain/release are paired correctly in other places you must not release your object in this case.

Sign up to request clarification or add additional context in comments.

Comments

0

If the NSArray (um, it is an NSArray, isn't it? C arrays provide no ownership management) is the only thing that owns the object -- that is, if the object added was acquired autorelease-d or you explicitly called release after adding -- then it will be cleaned up automatically on removal. Any other ownership claims will still need to be release-d as normal.

Comments

0

In fact, your talking about NSMutableArray

And it does the release 'automatically'. So do

[array add:  @"SAFEY-STRING" ];

and don't do

[array add:  [[NSString alloc] initWithFormat:@"LEAKY-STRING"] ];

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.