[]内存释放问题


export class ResUIModuleManager {
/**
* 模块资源路径
*/
private static moduleResPath: string = 'res/atlas/{0}.json';
/**
* 模块的资源名称和模块的主面板(模块的主面板类全名,模块资源图集名称[])
* @type {Laya.Dictionary}
* @memberof ResourcesModuleManager
*/
public static poolModulResDic: Laya.Dictionary = new Laya.Dictionary();
constructor() {
}
static gameLoading(name: string, onCompleted: Function): void {
let uiResArray = [
{ url: "res/atlas/common.json", type: Laya.Loader.ATLAS },
{ url: "res/atlas/comp.json", type: Laya.Loader.ATLAS }, // 登录的UI和选角的UI
{ url: "res/atlas/user.json", type: Laya.Loader.ATLAS },
{ url: resourcesCenter.ResourcesPathStr.PROTO_FILE_PATH, type: Laya.Loader.TEXT } // 协议文件
];
Laya.loader.load(uiResArray, Laya.Handler.create(this, onCompleted), Laya.Handler.create(this, ProgressPanel.showGameLoadingProgressPanel, null, false));
}
/**
* 显示一个模块面板
* 需要 资源altlas的名称和面板的类全名
* @static
* @param {string[]} resAltlasName
* @param {*} classFullName
*
* @memberof ResourcesModuleManager
*/
static showModuleAndLoadAltas(resAltlasName: string[], className: any, showCompleteFun: Function): void {
ResUIModuleManager.poolModulResDic.set(bigao.Utils.GlobalUtils.getClassNameClass(className), { resNames: resAltlasName, time: Laya.timer.currTimer });
ResUIModuleManager.loadModuleByName(resAltlasName, className, (cn) => {
let sv: any = ui.UIControl.instance.showView(cn);
showCompleteFun(sv);
});
}
/**
* 加载模块的资源
* 资源必须放在atlas下面
* @static
* @param {string[]} mNames 模块的资源路径下的名称(也是模块名称)
* @param {Function} onCompleted 加载成功后的回调
*
* @memberof ResourcesModuleManager
*/
static loadModuleByName(mNames: string[], className: any, onCompleted: Function): void {
let uiResArray = [];
let muduleName;
for (let index = 0, len = mNames.length; index < len; index++) {
muduleName = mNames[index];
uiResArray.push({ url: bigao.Utils.StringTool.formatString(ResUIModuleManager.moduleResPath, muduleName), type: Laya.Loader.ATLAS });
}
Laya.loader.load(uiResArray, Laya.Handler.create(this, onCompleted, [className]), Laya.Handler.create(this, ProgressPanel.showLoadingProgressPanel, null, false));
}
/**
* 清理一个模块的资源(图集)
*/
static cleanModuleAtlas(className: string): void {
let obj: Object = ResUIModuleManager.poolModulResDic.get(className);
if (!obj || !obj["resNames"]) return;
let moduleNames: string[] = obj["resNames"];
let muduleName: string;
let path: string;
for (let i = 0, len = moduleNames.length; i < len; i++) {
muduleName = moduleNames[i];
let curMem: number = Laya.Stat.currentMemorySize// >> 20;
console.log("curM:", curMem);
path = bigao.Utils.StringTool.formatString(ResUIModuleManager.moduleResPath, muduleName);
bigao.control.SkillControl.instance._skillView = null;
Laya.loader.clearRes(path, true); // 为什么这里clean了内存没有变化
curMem = Laya.Stat.currentMemorySize //>> 20;
console.log("curM:", curMem);
}
ResUIModuleManager.poolModulResDic.remove(className);
}
}
 
上面是封装了一个类来加载UI模块资源的,遇到一个问题就是 调用 “cleanModuleAtlas”后资源没有释放!
已邀请:

要回复问题请先

商务合作
商务合作