difference between [self.view release] and [view release]?
What is the di开发者_运维问答fference between
difference between [self.view release] and [view release].
I get a memory leak error in [self.view release]
[view release]
is calling NSObject
's - (void)release
method directly on an instance variable named view
.
[self.view release]
is calling - (UIView *)view
(I'm assuming view
is of type UIView
) on self
and then calling - (void)release
on the returned object.
There shouldn't be any practical difference. However, since one reason for using properties is to eliminate the need for explicit memory management, [self.view release]
would be a strange thing to do. If it's a property, let the property accessors retain and release the object as necessary.
It's hard to see why you'd get a real leak from [self.view release]
. Leaks come from failing to properly release an object -- I don't think you can create a leak by releasing something. It may be that accessing the object through a property prevents the static analyzer from connecting the dots from +alloc to -release.
精彩评论