测试用代码如下:
require "Cocos2d"
require "Cocos2dConstants"
require "scheduler"
-- cclog
cclog = function(...)
print(string.format(...))
end
-- for CCLuaEngine traceback
function __G__TRACKBACK__(msg)
cclog("----------------------------------------")
cclog("LUA ERROR: " .. tostring(msg) .. "\n")
cclog(debug.traceback())
cclog("----------------------------------------")
end
local plists = {
"1.plist",
"2.plist",
"3.plist",
"4.plist",
"5.plist",
"6.plist",
"7.plist",
"8.plist",
"9.plist",
}
local frameCache = cc.SpriteFrameCache:getInstance()
local textureCache = cc.TextureCache:getInstance()
local scheduler = cc.Director:getInstance():getScheduler()
function load()
local plistLoaded = 0
local plistCount = #plists
local sche
sche = scheduler:scheduleScriptFunc(function()
if plistLoaded < plistCount then
plistLoaded = plistLoaded + 1
frameCache:addSpriteFramesWithFile(plists)
print("plistLoaded: ", plistLoaded)
else
frameCache:removeUnusedSpriteFrames()
textureCache:removeAllTextures()
scheduler:unscheduleScriptEntry(sche)
print("........................................")
print(cc.TextureCache:getInstance():getCachedTextureInfo())
print("........................................")
end
end, 1, false)
end
local function main()
local scene = cc.Scene:create()
local layer = cc.Layer:create()
cc.Director:getInstance():runWithScene(scene)
load()
end
local status, msg = xpcall(main, __G__TRACKBACK__)
if not status then
error(msg)
end
```
情况一:
执行如上代码,getCachedTextureInfo()输出情况为: TextureCache dumpDebugInfo: 0 textures, for 0 KB (0.00 MB)
任务管理器看内存使用情况:43 340 K
而且这里我在Texture2D::~Texture2D()中GL::deleteTexture(_name);处加断点发现确实执行了,纹理应该是释放了
情况二:
注释掉 load(),getCachedTextureInfo()输出情况为: TextureCache dumpDebugInfo: 0 textures, for 0 KB (0.00 MB)
任务管理器看内存使用情况:25 312 K
情况一中加载过纹理但是已经释放,为啥内存没有降下来?