内存泄露检测

This commit is contained in:
宝爷
2020-12-13 22:28:25 +08:00
parent 410dc9a7a0
commit c7f973956f
3 changed files with 4617 additions and 4615 deletions

View File

@@ -12,6 +12,8 @@
* 2020-1-20 by 宝爷
*/
import { ResUtil } from "./ResUtil";
export type FilterCallback = (url: string) => boolean;
export class ResLeakChecker {
@@ -19,37 +21,6 @@ export class ResLeakChecker {
private _checking: boolean = false;
private _log: Map<string, Map<string, string>> = new Map<string, Map<string, string>>();
static findCharPos(str: string, cha: string, num: number): number {
let x = str.indexOf(cha);
let ret = x;
for (var i = 0; i < num; i++) {
x = str.indexOf(cha, x + 1);
if (x != -1) {
ret = x;
} else {
return ret;
}
}
return ret;
}
static getCallStack(popCount: number): string {
/*let caller = arguments.callee.caller;
let count = Math.min(arguments.callee.caller.length - popCount, 10);
let ret = "";
do {
ret = `${ret}${caller.toString()}`;
caller = caller && caller.caller;
--count;
} while (caller && count > 0)*/
let ret = (new Error()).stack;
let pos = ResLeakChecker.findCharPos(ret, '\n', popCount);
if (pos > 0) {
ret = ret.slice(pos);
}
return ret;
}
public checkFilter(url: string): boolean {
if (!this._checking) {
return false;
@@ -71,7 +42,7 @@ export class ResLeakChecker {
if (urlInfos.has(use)) {
console.warn(`ResLeakChecker doubel same use ${url} : ${use}, stack ${urlInfos[use]}`);
}
urlInfos.set(use, stack ? stack : ResLeakChecker.getCallStack(2));
urlInfos.set(use, stack ? stack : ResUtil.getCallStack(2));
}
public logRelease(url: string, use: string) {

View File

@@ -182,6 +182,37 @@ export class ResUtil {
return node;
}
static findCharPos(str: string, cha: string, num: number): number {
let x = str.indexOf(cha);
let ret = x;
for (var i = 0; i < num; i++) {
x = str.indexOf(cha, x + 1);
if (x != -1) {
ret = x;
} else {
return ret;
}
}
return ret;
}
static getCallStack(popCount: number): string {
/*let caller = arguments.callee.caller;
let count = Math.min(arguments.callee.caller.length - popCount, 10);
let ret = "";
do {
ret = `${ret}${caller.toString()}`;
caller = caller && caller.caller;
--count;
} while (caller && count > 0)*/
let ret = (new Error()).stack;
let pos = ResUtil.findCharPos(ret, '\n', popCount);
if (pos > 0) {
ret = ret.slice(pos);
}
return ret;
}
// /**
// * 获取一系列节点依赖的资源
// */

9166
creator.d.ts vendored

File diff suppressed because it is too large Load Diff