My object is not getting released from memory so I override retain method and put a breakpoint in to see where in code it gets retained.
Every time the object is referenced using a property accessor the retain method is called. Why would this be happening?
color = self.myobject.color
calls retain.
The synthesized property accessor for retained properties looks something like this:
Therefore, your
retainmethod is called, but it’s balanced with anautorelease.See this code snippet in the Objective-C Programming Language Guide for an example of how a synthesized accessor might look (the locking part doesn’t apply in the nonatomic case, but the retain-autorelease is the same).