3 ms·
"The equivalent to Java’s this is pretty much self." Well no, the difference (inside a class) of: this.foo = myshinyobject and foo = myshinyobject is nothi
by einarvollset 17y ago
"The equivalent to Java’s this is pretty much self."
Well no, the difference (inside a class) of:
this.foo = myshinyobject
and
foo = myshinyobject
is nothing in Java. In Objective-C,
self.foo = myshinyobject
and
foo = myshinyobject
are different. Particularly with regards to the @property (retain) magic; if you forget self.foo and use foo, then myshinyobject might get garbage collected. Which is not what you'd expect with a retained property.
- tumult 17y agoWell, on iPhone, it would get deallocated with the next pool drain, not garbage collected (since garbage collection does not exist for iPhone as of now.) foo = myshinyobject is ok if you use instantiate it like [[SomeClassThing alloc] initetc] rather than one of the convenience methods like [SomeClassThing thing] since those are supposed to be returned with a retain count of 0. I forgot what I was getting at.
- einarvollset 17y agoWell, sort of. If you do an alloc/init, then you need to release it (or you leak). If you're assigning to self.foo, then you can just release the thing you created after assigning it. If you assigned it to foo, and then release it, then you're in the position I mentioned above.