Reputation: 1
I was trying to track a strage memory allocation bug so I overrode the retain and release methods of my class. I noticed that when assigning an instance of this class to a property of another, the retain count of the object increased, but my redefined retain was never called.
How can this be possible? Are (retain) properties retaining the object without calling retain?
Upvotes: 0
Views: 332
Reputation: 41
if you don't use self (self.yourproperty), it won't increase the retain count.
Upvotes: 0
Reputation: 49354
Is garbage collection turned on? I don't believe retain
is called under GC.
Upvotes: 0
Reputation: 34185
In my machine, the overridden retain
was called. (I'm using 10.6.4. I checked this both on GCC 4.2.1 and clang 1.5.)
Could you post your code?
Internally, the synthesized setter for a retain
property uses objc_setProperty
, the source code of which is available here.
As you see, eventually it calls [newObject retain]
when the property uses retain
.
Upvotes: 3
Reputation: 15625
I wouldn't be surprised if synthesized properties would modify the retain count without calling retain or release.
Upvotes: -1