I have been playing a bit with the memory in order to be a good memory citizen on the iPhone SDK.
However I still struggle to understand the difference between “self.something” and just “something”.
As far as I understood, “self.something” means ask to the class for “something”, but there is something wrong on my thought. Let’s see the example:
I have worked with the memory releasing:
[self.labelIBOUtlet release]-> It crash[labelIBOUtlet release]-> It doesn’t.
Can anyone please explain me what is the reason?
Thank you!
EDIT:
This is the information I have set on the header file:
@interface viewController : UIViewController {
UILabel * labelIBOutlet ;
}
@property (nonatomic,retain) IBOutlet UILabel * labelIBOutlet ;
You have to understand the meaning of “property”
the use of “dot” is just a faster way to call “special methods” created just to “set” and “get” variable-property.
as example, you could have your own class/UIView which uses a subView:
in myView.h
if you do just this you have not a “property”, but just an ojbect…
so in your myView.m you try to use the “dot” like this:
then you get an error, you cannot do that, xCode says:
error: accessing unknown ‘webView’ getter method
that just means that a the method “webView” doesn’t exist…
‘couse when you call “self.webView” you just call a method called “webView”…
this method just return the pointer to your value.
and when you call:
you are just calling the method “setWebView”, a method that just set your object with someValue…
but so… where do those 2 invisible methods come from?
they are created by xCode itself if you tell it to use webView as a property…
in our example, add some lines:
in myView.h
in myView.m
doing this xCode will add the 2 methods “webView” and “setWebView” for you,
and now you can call:
with no error…
and you can put value (of the right format, in this case a pointer to an existing UIWebView)
just calling:
and remember to release it, ‘couse you used “retain” in :
release it with: