Releasing properties
I have two NSStrings and those are also having the property, synthesize. Is there any need t开发者_Python百科o release those objects?
If the property is either copy or retain you have to release the ivar. If the value is just assigned you must not release.
Yes! Anything which is pointer type which is made property & synthesise should be released
Whether you should call release actually depends.
If you called alloc+init, and then assigned to the property, then you do have to release. The reason is that alloc+init increases the reference count by 1, so you have to have a corresponding release to return the reference count to 0. The release should be in the dealloc method of the class.
However, it's possible to use those properties without calling alloc+init too. Then generally you don't have to call release. For example if you use self.property = [NSString stringWithFormat:@"..."], then there is no need to call release, actually calling release would be wrong.
Furthermore, you may also decide to autorelease objects, which tells the autorelease pool to automatically release objects at a later time. This is another case where you don't have to manually release the object.
精彩评论