Quote:
Originally Posted by sajjadzare
if i declare NSString *a=[[NSString alloc]...]
Does it neccessary to relese a
if yes
Why ?
Where should i relese it ?
if i don't relese it what happen ?
|
Yes, "a" must be released because "alloc" causes memory to be allocated to contain the NSString object. If you do not ever release it, then that memory cannot be used for anything else. And if you do this over and over again in your app, you will allocate more and more memory, until you run out of memory and your app stops working.
Where should you release it? Anywhere in the code that did the alloc after the last point where that code needs to access it. This does not cover other objects that may have done a retain on their own, such as when you add the NSString to something. If you do that, then the other object has the responsibility to do another release when it is done. You can safely do a release without worrying about when that other object is going to be done with it.
Robert Scott
Ypsilanti, Michigan