-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
54 lines (41 loc) · 1.29 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
var MemCleaner = (function() {
var instance
if (global.gc) {
console.log('Garbage collector is available on global scope')
} else {
console.log('--expose-gc flag wasn\'t provided')
}
var set = function(interval) {
return global.gc ? setInterval(function() {
try {
global.gc()
} catch (gcerr) {
console.log('Garbage collecting error', gcerr)
}
}, interval) : undefined
}
var createInstance = function(interval) {
if (interval < 1000) {
console.log('gc cleaner interval set to 1 second')
interval = 1000
}
if (instance) {
clearInterval(instance)
}
return set(interval)
}
instance = set(30000)
return function Construct_singletone(interval) {
if (!global.gc) return
interval = parseInt(interval) || 30000
console.log('Setting garbage collector periodic task with interval', interval, 'ms')
instance = createInstance(interval)
return instance
if (this && this.constructor === Construct_singletone) {
instance = this
} else {
return new Construct_singletone()
}
}
}())
module.exports = MemCleaner