
7
I have the following method
I am not releasing the aPais, because if I do it the application crashes. I don't know when or if whether I should release it somewhere after using it and, if so, how do I do it. Just release the NSMutableArray is enough? Or do I have to traverse it and release each object?
And if I don't have to release it, who is the responsible for releasing?
<a href="http://stackoverflow.com/users/46354/andynormancx"></a>
<a href="http://stackoverflow.com/users/46354/andynormancx">andynormancx</a>
3,2711026
asked Mar 2 '09 at 12:38
<a href="http://stackoverflow.com/users/72740/sacha-fuentes"></a>
<a href="http://stackoverflow.com/users/72740/sacha-fuentes">Sacha Fuentes</a>
4514
feedback
<a></a>
As epatel said, you don't need to release that particular string. If you wanted to be more proactive, you could do this instead:
In summary:
[[NSString alloc] initWith...] -> You must release or autorelease.
[NSString stringWith...] -> No need to release.
-- Edit: Added <code>autorelease</code> for paises, as you are returning it. When you return an object, always autorelease it if you have alloc&init'd it.
answered Mar 2 '09 at 13:01
<a href="http://stackoverflow.com/users/42690/squelart"></a>
<a href="http://stackoverflow.com/users/42690/squelart">squelart</a>
2,258717

<code>stringWithUTF8String:</code> returns an autorelease string which will be released automatically by Cocoa in the next eventloop. But the string is also retained in the array when you do <code>addObject:</code>...so as long as it is in the array it will be retained.
answered Mar 2 '09 at 12:48
<a href="http://stackoverflow.com/users/842/epatel"></a>
<a href="http://stackoverflow.com/users/842/epatel">epatel</a>
16.8k83876
Was this post useful to you?
歡迎加群互相學習,共同進步。QQ群:iOS: 58099570 | Android: 572064792 | Nodejs:329118122 做人要厚道,轉載請注明出處!
本文轉自張昺華-sky部落格園部落格,原文連結:http://www.cnblogs.com/sunshine-anycall/archive/2011/10/21/2219738.html,如需轉載請自行聯系原作者