release and retain with member variables

I’m not quite understand about the release and retain when use member variables.
For example:
class A : public CCLayer
{
public:
A ();
virtual ~A();
CREATE_FUNC(A);
virtual bool init();
protected:
CCString *mStr;
};

A::A ()
{
mStr=NULL;
}
bool A::init()
{
bool bRet=false;
while(0)
{
CC_BREAK_IF(CCLayer::init());

mStr=CCString::create(“abc”);
mStr->retain();

bRet=true;
}
return bRet;
}

Now I have the question that do I need to call “mStr->release()” int the A\ function?
In\ fact\ I\ have\ tried\ runing\ the\ program\ without\ calling\ the\ “mStr->release()”\ int\ the
A function and got no errors.
I don’t know whether this is right,could somebody please help me?

Simple answer, yes you need to call release on any CCObject you retain explicitly. Otherwise you won’t get an error but you will get a memory leak. This is not about member variables, this is about how the engine refcount system works.

Best way to find the answer and to learn is to grab a coffee, go out there and use breakpoints. Have you tried putting one in the CCString destructor? What happens when you create a CCString and don’t call retain on it? What does the callstack looks like? Whad happens if you do call retain? Does the CCString destructor ever gets called upon program termination in that case?

Have fun and good luck!

Very exhaustive,now I get the point,thank you very much!