Commit d8cfefff authored by liujiangnan's avatar liujiangnan

debug: 新型释放内存

parent d603f89e
......@@ -343,19 +343,16 @@
"__id__": 512
},
{
"__id__": 514
},
{
"__id__": 524
"__id__": 522
}
],
"_active": true,
"_components": [
{
"__id__": 534
"__id__": 532
},
{
"__id__": 535
"__id__": 533
}
],
"_prefab": null,
......@@ -24770,78 +24767,6 @@
"_originalHeight": 0,
"_id": "b2OIHmdDVFT5aJppIyFhCT"
},
{
"__type__": "cc.Node",
"_name": "Destroyer",
"_objFlags": 0,
"_parent": {
"__id__": 7
},
"_children": [],
"_active": false,
"_components": [
{
"__id__": 513
}
],
"_prefab": null,
"_opacity": 255,
"_color": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"_contentSize": {
"__type__": "cc.Size",
"width": 0,
"height": 0
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_trs": {
"__type__": "TypedArray",
"ctor": "Float64Array",
"array": [
0,
0,
0,
0,
0,
0,
1,
1,
1,
1
]
},
"_eulerAngles": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_skewX": 0,
"_skewY": 0,
"_is3DNode": false,
"_groupIndex": 0,
"groupIndex": 0,
"_id": "d9WooRoG1L444hPQOE3zBg"
},
{
"__type__": "ddd21vavV5OAZOK6TPHd3Je",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 512
},
"_enabled": true,
"_id": "04XtlEx3hD9J2J8VGhgzZI"
},
{
"__type__": "cc.Node",
"_name": "exception_pay_win",
......@@ -24851,22 +24776,22 @@
},
"_children": [
{
"__id__": 515
"__id__": 513
},
{
"__id__": 517
"__id__": 515
},
{
"__id__": 519
"__id__": 517
}
],
"_active": false,
"_components": [
{
"__id__": 522
"__id__": 520
},
{
"__id__": 523
"__id__": 521
}
],
"_prefab": null,
......@@ -24922,13 +24847,13 @@
"_name": "bg",
"_objFlags": 0,
"_parent": {
"__id__": 514
"__id__": 512
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 516
"__id__": 514
}
],
"_prefab": null,
......@@ -24984,7 +24909,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 515
"__id__": 513
},
"_enabled": true,
"_materials": [
......@@ -25016,13 +24941,13 @@
"_name": "buy_status_text",
"_objFlags": 0,
"_parent": {
"__id__": 514
"__id__": 512
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 518
"__id__": 516
}
],
"_prefab": null,
......@@ -25078,7 +25003,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 517
"__id__": 515
},
"_enabled": true,
"_materials": [
......@@ -25111,16 +25036,16 @@
"_name": "active_btn",
"_objFlags": 0,
"_parent": {
"__id__": 514
"__id__": 512
},
"_children": [],
"_active": false,
"_components": [
{
"__id__": 520
"__id__": 518
},
{
"__id__": 521
"__id__": 519
}
],
"_prefab": null,
......@@ -25176,7 +25101,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 519
"__id__": 517
},
"_enabled": true,
"_materials": [
......@@ -25208,7 +25133,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 519
"__id__": 517
},
"_enabled": true,
"_normalMaterial": null,
......@@ -25276,7 +25201,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 514
"__id__": 512
},
"_enabled": true,
"alignMode": 1,
......@@ -25303,7 +25228,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 514
"__id__": 512
},
"_enabled": true,
"_id": "63cvkRlSFBkLFRxtfV9h6g"
......@@ -25317,16 +25242,16 @@
},
"_children": [
{
"__id__": 525
"__id__": 523
},
{
"__id__": 528
"__id__": 526
}
],
"_active": false,
"_components": [
{
"__id__": 533
"__id__": 531
}
],
"_prefab": null,
......@@ -25382,16 +25307,16 @@
"_name": "bg",
"_objFlags": 0,
"_parent": {
"__id__": 524
"__id__": 522
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 526
"__id__": 524
},
{
"__id__": 527
"__id__": 525
}
],
"_prefab": null,
......@@ -25447,7 +25372,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 525
"__id__": 523
},
"_enabled": true,
"_materials": [
......@@ -25479,7 +25404,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 525
"__id__": 523
},
"_enabled": true,
"alignMode": 1,
......@@ -25506,20 +25431,20 @@
"_name": "tips",
"_objFlags": 0,
"_parent": {
"__id__": 524
"__id__": 522
},
"_children": [
{
"__id__": 529
"__id__": 527
}
],
"_active": true,
"_components": [
{
"__id__": 531
"__id__": 529
},
{
"__id__": 532
"__id__": 530
}
],
"_prefab": null,
......@@ -25575,13 +25500,13 @@
"_name": "label",
"_objFlags": 0,
"_parent": {
"__id__": 528
"__id__": 526
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 530
"__id__": 528
}
],
"_prefab": null,
......@@ -25637,7 +25562,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 529
"__id__": 527
},
"_enabled": true,
"_materials": [
......@@ -25670,7 +25595,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 528
"__id__": 526
},
"_enabled": true,
"_materials": [
......@@ -25702,7 +25627,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 528
"__id__": 526
},
"_enabled": true,
"alignMode": 1,
......@@ -25729,7 +25654,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 524
"__id__": 522
},
"_enabled": true,
"alignMode": 1,
......
cc.Class({
extends: cc.Component,
start() {
this.middleLayer = cc.find('middleLayer').getComponent('middleLayer');
},
onDestroy() {
console.log('喵喵喵: destroyer onDestroy');
this.middleLayer.clearDragonDisplayAssetList();
}
});
{
"ver": "1.0.8",
"uuid": "ddd21bda-bd5e-4e01-938a-e933c777725e",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}
\ No newline at end of file
......@@ -210,38 +210,45 @@ export abstract class middleLayerBase extends cc.Component {
this.loadBundle(sceneName, version, bondleUrl);
}
cleanMemory() {
// 释放骨骼动画
const deepDrog = (nd) => {
const dragonDisplay = nd.getComponent(dragonBones.ArmatureDisplay);
if (dragonDisplay) {
dragonDisplay.destroy();
}
nd.children.forEach(child => {
deepDrog(child);
});
}
deepDrog(cc.find("Canvas"));
// 释放bundle
const bd = cc.assetManager.getBundle(this.oldSceneName);
bd.releaseAll();
cc.assetManager.removeBundle(bd);
// 释放远程加载的资源
cc.assetManager.assets.forEach(item => {
if(item.nativeUrl.indexOf(`h5template`)==-1 && item.nativeUrl.indexOf(`dist`)==-1 && item.nativeUrl.indexOf(`http`)>-1) {
cc.assetManager.releaseAsset(item);
}
});
}
async loadBundle(sceneName, version, bondleUrl, callback = null) {
if (this.oldSceneName) {
await this.checkRotateScreen(this.oldSceneName, sceneName);
}
this.assetList = [];
this.textureList = [];
this.assetObj = {};
this.atlasList = [];
this.nodeList = [];
this.getDragonDisplayAssetList(cc.find('Canvas'));
// this.toCleanParent();
this.loadBundleLock = true; // 加锁
this.currentBundleInfo = { sceneName, version, bondleUrl };
this.showWaitingLetters();
cc.audioEngine.stopAll();
this.setNodeListVisible();
// 手机端强制垃圾回收
if (cc.sys.os == cc.sys.OS_IOS || cc.sys.os == cc.sys.OS_ANDROID) {
cc.sys.garbageCollect();
}
this.cleanMemory();
cc.assetManager.loadBundle(bondleUrl, { version: version }, async (err, bundle) => {
bundle.loadScene(sceneName, null, (finish, total, item) => {
this.setLoadingProgressBar(Math.floor(finish / total * 100));
}, (err, scene) => {
this.loadBundleLock = false; // 加载完成 解锁
this.courseOpenTimeStamp = Date.now();
......@@ -256,17 +263,6 @@ export abstract class middleLayerBase extends cc.Component {
canvas.getComponent(cc.Widget).updateAlignment();
middleLayer.scale = canvas.width / middleLayer.width;
// 挂载清洁骨骼机制节点
const destroyer = cc.instantiate(cc.find('middleLayer/Destroyer'));
destroyer.parent = cc.find('Canvas');
destroyer.active = true;
// 手机端强制垃圾回收
if (cc.sys.os == cc.sys.OS_IOS || cc.sys.os == cc.sys.OS_ANDROID) {
cc.sys.garbageCollect();
}
callback && callback();
this.IS_BUNDLE_LOADING = false;
this.oldSceneName = sceneName;
......@@ -290,20 +286,6 @@ export abstract class middleLayerBase extends cc.Component {
}
setNodeListVisible() {
const setParentVisible = (n) => {
// TODO active" is not defined in the Scene, it is only defined in normal nodes
n.active = true;
if (n.parent) {
setParentVisible(n.parent);
}
}
this.nodeList.forEach(node => {
setParentVisible(node);
});
}
getUUID() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
var r = Math.random() * 16 | 0,
......@@ -484,100 +466,4 @@ export abstract class middleLayerBase extends cc.Component {
.start();
}
async clearDragonDisplayAssetList() {
if (this.atlasList.length == 0) {
return;
}
this.setNodeListVisible();
for (let i=0; i<this.atlasList.length; i++) {
const atlas = this.atlasList[i];
const asset = this.assetList[i];
const texture = this.textureList[i];
const node = this.nodeList[i];
atlas.decRef();
cc.assetManager.releaseAsset(atlas);
atlas.destroy();
asset.decRef();
cc.assetManager.releaseAsset(asset);
asset.destroy();
// node.active = false;
// node.removeFromParent();
texture.decRef();
}
}
// 原始方法
clearDragonDisplayAssetList3() {
[ ...this.atlasList , ...this.assetList].forEach(asset => {
asset.decRef();
cc.assetManager.releaseAsset(asset);
asset.destroy();
});
this.nodeList.forEach(node => {
node.active = false;
node.removeFromParent();
});
this.textureList.forEach(texture => {
texture.decRef();
});
}
assetObj = null;
nodeList = null;
atlasList = null;
assetList = null;
textureList = null;
getDragonDisplayAssetList(node) {
const dragonDisplay = node.getComponent(dragonBones.ArmatureDisplay);
if (dragonDisplay) {
const atlas = dragonDisplay.dragonAtlasAsset;
const asset = dragonDisplay.dragonAsset;
if (atlas && atlas.texture) {
if (atlas.texture.nativeUrl.includes('h5template')) {
node.children.forEach(child => {
this.getDragonDisplayAssetList(child);
});
return;
}
this.nodeList.push(node);
this.atlasList.push(atlas);
this.assetList.push(asset);
this.textureList.push(atlas.texture);
console.log('汪汪汪: atlas.texture.nativeUrl = ' + atlas.texture.nativeUrl);
}
}
node.children.forEach(child => {
this.getDragonDisplayAssetList(child);
});
}
toCleanParent() {
const canvas = cc.find("Canvas");
this.nodeList.forEach(node => {
node.parent = canvas;
});
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment