I guess I still don’t understand this yet. I’m not using ARC on this project.
For a propert, aProperty declared with the retain attribute, I would expect that the assigned object is retained twice in the following statement:
self.aProperty = [UIView alloc] init...];
Once from the alloc, and once by the setter.
So I release the object once immediately, like this:
self.aProperty = [UIView alloc] init...];
[self.aProperty release];
The compiler gives an error message:
Incorrect decrement of reference count of an object that is not owned at this point
by the caller.
Is the retain count incremented by the setter, making it two, at that point?
Also, what does “not owned at the point by the caller” mean? This could be a problem that I’m not familiar with.
To clarify what is happening.
is equivalent to calling
When using a
@propertywith retain it’s implementation would end up looking something like this (this is just a rough example)So now we can say that
and
which is +2 for the count. We then would have something like
which is -1, which just leaves us with a memory leak as there is stil +1 retain.
The pattern I favour is
so that memory is released as soon as possible and no dangling pointers are left as it is
nil‘led out