Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
A tool for check the memory leak.
branch: master

This branch is even with JacksonTian:master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
.gitignore
README.md
example.js
master.js
testcase.js
worker.js

README.md

leakchecker

A tool for check the memory leak.

调用方法

var checker = require('./master.js');
var TestCase = checker.TestCase;

var cases = [];
// 添加case,参数分别为case名字,模块路径,方法名,参数数组(可选)
cases.push(new TestCase("leak", "./testcase.js", "leak"));
cases.push(new TestCase("noleak", "./testcase.js", "noleak"));

// 执行cases,2分钟后等数据报告吧。
checker.start(cases);

2分钟后:

jackson-mac:leakchecker jacksontian$ node example.js 
Case noleak:
[ { rss: 11628544, heapTotal: 5046720, heapUsed: 2242504 },
  { rss: 11324948, heapTotal: 4778877, heapUsed: 2475885 },
  { rss: 10432512, heapTotal: 3752320, heapUsed: 1978472 } ]
您滴方法是安全滴
Case leak:
[ { rss: 11837440, heapTotal: 5046720, heapUsed: 2233696 },
  { rss: 21895741, heapTotal: 14923174, heapUsed: 11606990 },
  { rss: 21319680, heapTotal: 13630976, heapUsed: 11684104 } ]
疑似内存泄漏

原理

通过编写case设置,让检查工具创建worker进程,然后引入模块,调用方法20000次,每隔1秒查看一次内存,然后2分钟后检查内存,向工具报告最初内存状况,平均内存状况,最后内存状况,然后退出进程。如果最后内存状况比平均内存要高,则必然是有内存泄漏。如果低于平均内存,但是比初始内存还高1M的话,则疑似内存泄漏。其他情况下表明安全。

方法很土。欢迎意见和建议。

Something went wrong with that request. Please try again.