【已解决】【内存问题】使用官方释放方法释放动作json,释放不全面。内存越来越大

— Begin quote from ____

关于内存不释放。官方已经给出解决方案
特此感谢hanrea 和2youyouo2
解决办法:
cocos2d-x / extensions / CocoStudio / Armature / utils / CCDataReaderHelper.cpp
384行 加一行:标红内容

else
if(str.compare(".json")
==0
||str.compare(".ExportJson")
==0)
{
CCDataReaderHelper
::addDataFromJsonCache(load_str.c_str(),
&dataInfo);
}

CC_SAFE_DELETE_ARRAY(pBytes);
}
如果找不到pBytes。请看368行

unsigned
char
*pBytes
= CCFileUtils
::sharedFileUtils()
->getFileData(fullPath.c_str() , “r”,
&size);;
声明的什么就写什么。

— End quote

亲爱的版主。官方工作人员。
我公司正在用cocostudio做骨骼动画。
游戏内有大量动画。但是我们发现运行几次就会崩溃。
最后找到问题。释放内存不全面。 导致运行越久内存越大。直到崩溃。
还有个问题就是异步调用。释放内存无效。内存一点都没减少。
void HelloWorld::menuCloseCallback(CCObject* pSender)
{
aaa+=1;
if(aaa== 1){
test = CCSprite::create(“senlin.png”); //加载森林图片 监控内存变化
test->setPosition(ccp(0,0));
this->addChild(test);
}else if (aaa== 2) {
test->removeFromParent();
CCTextureCache::sharedTextureCache()->removeAllTextures(); //移出森林图片。 内存恢复原大小
}else if(aaa== 3){
CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo(“Armature/arm_10/100.png”,“Armature/arm_10/100.plist”,“Armature/arm_10/10.ExportJson”);//加载骨骼动画文件 检查内存变化。
armature = CCArmature::create(“10”);
armature->getAnimation()->setMovementEventCallFunc(this, movementEvent_selector(HelloWorld::Huidiao));
armature->setPosition(ccp(0,150));
this->addChild(armature,5);
armature->getAnimation()->play(“load”);

    CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("Armature/arm_217/2170.png","Armature/arm_217/2170.plist","Armature/arm_217/217.ExportJson");//加载骨骼动画文件
    armature2 = CCArmature::create("217");
    armature2->getAnimation()->setMovementEventCallFunc(this, movementEvent_selector(HelloWorld::Huidiao2));
    armature2->setPosition(ccp(150,150));
    this->addChild(armature2,5);
    armature2->getAnimation()->play("load");

    CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("Armature/arm_235/2350.png","Armature/arm_235/2350.plist","Armature/arm_235/235.ExportJson");//加载骨骼动画文件
    armature3 = CCArmature::create("235");
    armature3->getAnimation()->setMovementEventCallFunc(this, movementEvent_selector(HelloWorld::Huidiao3));
    armature3->setPosition(ccp(300,150));
    this->addChild(armature3,5);
    armature3->getAnimation()->play("load");
}else if(aaa== 4){
    armature2->getAnimation()->play("atk");
}else if(aaa==5){
    armature->getAnimation()->play("atk");
}else{
    armature3->getAnimation()->play("atk");
}

}

void HelloWorld::Huidiao(cocos2d::extension::CCArmature *armature, cocos2d::extension::MovementEventType type, const char *str){ //移出动画 发现内存没有回原大小。 3个都移出后 内存比原大小增加了0.7MB左右
if(type == COMPLETE){
armature->removeFromParent();
//armature->removeFromParentAndCleanup(true);
CCArmatureDataManager::sharedArmatureDataManager()->removeArmatureFileInfo(“Armature/arm_10/10.ExportJson”);
CCTextureCache::sharedTextureCache()->removeAllTextures();
}
}

void HelloWorld::Huidiao2(cocos2d::extension::CCArmature *armature, cocos2d::extension::MovementEventType type, const char *str){
if(type == COMPLETE){
armature->removeFromParent();
//armature->removeFromParentAndCleanup(true);
CCArmatureDataManager::sharedArmatureDataManager()->removeArmatureFileInfo(“Armature/arm_217/217.ExportJson”);
CCTextureCache::sharedTextureCache()->removeAllTextures();
}
}

void HelloWorld::Huidiao3(cocos2d::extension::CCArmature *armature, cocos2d::extension::MovementEventType type, const char *str){
if(type == COMPLETE){
armature->removeFromParent();
//armature->removeFromParentAndCleanup(true);
CCArmatureDataManager::sharedArmatureDataManager()->removeArmatureFileInfo(“Armature/arm_235/235.ExportJson”);
CCTextureCache::sharedTextureCache()->removeAllTextures();
}
}

楼主你好,谢谢反馈,这个问题我今天会联系动作编辑器的工程师来跟进,你可以加一下我的Q,方便联系。:7:

我也遇到了同样的问题。。。

我也遇到了同样的问题。。。

我也遇到了同样的问题。。。

这个确实是有。
看下 这个commit :
https://github.com/2youyouo2/cocos2d-x/commit/982ae649c69ae35c91d71d12cb0e84b3837c1fd5

3.0的也都失效呢。

官方已经给出解决方案
特此感谢hanrea 和2youyouo2

楼主,你的问题确认解决了么?内存保持稳定?

解决了 以前添加3个释放后 内存会大2mb
现在就大0.02mb

这是针对几点几版本的啊?

怎么解决解决?

如何看到手机内存使用//

我这边倒是没用到骨骼动画,几乎是一些cocosstudio编辑的静态界面,但是资源还是释放不了啊啊

这个都是使用内存检测工具测试的,可以看你的IDE工具附带的功能。

221里添加代码:
CC_SAFE_DELETE_ARRAY(pBytes);
pBytes找不到变量。。。。。。


const char *pFileContent = (char *)CCFileUtils::sharedFileUtils()->getFileData(fullPath.c_str() , “r”, &size);
好吧,变量名不一样。。。版本差不少。。。
有用221的没?这个问题有没有?

这个问题是因为 SpriteFrameCache 增加了 texture的 引用计数,导致在 texture 不能释放spriteFrameCache引用的 texture.我的解决方法是 先removeSpriteFrameCache,然后再释放不使用的 texture

楼主,版主给的解决方法具体怎么用啊?就以你贴的代码为例!谢谢啦

版主,这个问题提供的解决方法具体怎么用啊?CCDataReaderHelper::addDataFromJsonCache(load_str.c_str(), &dataInfo);
方法里应该写什么啊?