CCString Lost the value?

My class is the sub class of CCSprite and content same protected CCString variable, after I create the object, the CCString will lose the value. But when I change it to a std:string, every thing is well.

I create the CCString in the constructor
@
.h
class a: public CCSprite{
protected:
CCString* text;

//.cpp
a(){
text = CCString::create(“ABC”);
}
@

Are you retaining the CCString after creating it?
Creating it with the create method it gets autoreleased at the end of the block.

I have not call: text->retain();

Gary K wrote:

I have not call: text->retain();

Did that resolve your problem?

I had try to call retain() but it is not work.

Can you paste code of your constrcutor and the function where you use the string so i can see where is the problem?

`bool Building::init(CCDictionary* buildingDict, CCString* key, CCString* spriteFileName){
CCAssert(spriteFileName != NULL, “Invalid filename for sprite”);

if ( !CCSprite::initWithFile(spriteFileName->getCString()))
{
return false;
}
key_ = key->getCString();
buildingDict_ = buildingDict;
name_ = buildingDict->valueForKey(“Building_Name”);
return true;
}`

name_ is a protected variable declared in .h

void Building::update(float fDelta) { updateDebugInfo(); }

void Building::updateDebugInfo(){ if(isDebug && isShowBuildingInfo){ ((CCLabelTTF*)(debugLabelList[index]))->setString(CCString::createWithFormat("Building Name: %s", name_->getCString())->getCString()); } }

I had check by setting break points after assign value and before use name_

Anyway, I had solved this problem by change the type of name_ from CCString* to std::string, but I also want to find out the solution

I’m sorry but the only thing that seems wrong to me is the missing call of retain after setting its value:

name_->retain();

I don’t see why it cannot work.

Anyway, thanks for your help