由于更新大量文件(gulp,watch)而导致的内存泄漏

时间:2019-01-30 12:06:47

标签: javascript node.js gulp frontend

项目结构如下

app
=global //include for all pages
====component_1
====component_2
==pages 
====page_1
======page_1.css
======page_1.jade
======page_1.js
dist (place for build)
==page_1    
====global
======main.js
====page_1.js
====page_1.css
====index.html

有一个任务可以监视页面更改。

*。js示例

const JSPageWatcher= gulp.watch('app/pages/**/*.js') //такая же на CSS и Jade
  JSPageWatcher.on('change', e => {
    console.log('File ' + e + ' was, running tasks...')
    slideJS(e.split('\\').pop().replace('.js', '')) 
  })

对于组件

 gulp.watch('app/components/*.js', gulp.series('webpack'))

足以在IDE中打开组件文件,并且观察者将开始更新所有页面,并且观察者将在每种类型的页面文件之后开始工作,因为许多页面的消息会散布到控制台上

app\pages\4_44\4_44.css
File app\pages\4_44\4_44.css, running tasks...
File app\pages\4_45_D\4_45_D.js was, running tasks...
app\pages\4_45\4_45.css
File app\pages\4_45\4_45.css, running tasks...
app\pages\4_48\4_48.css
File app\pages\4_48\4_48.css, running tasks...
app\pages\4_46\4_46.css
File app\pages\4_46\4_46.css, running tasks...

所有这些显然都已缓存,最终崩溃,并显示如下错误:

<--- Last few GCs --->

[1644:000001A56BBA23F0]  6744991 ms: Mark-sweep 1371.8 (1425.1) -> 1371.4 (1425.1) MB, 1043.3 / 3.2 ms  (average mu = 0.150, current mu = 0.018) allocation failure scavenge might not succeed
[1644:000001A56BBA23F0]  6746176 ms: Mark-sweep 1372.1 (1425.1) -> 1371.7 (1425.1) MB, 1172.5 / 6.4 ms  (average mu = 0.083, current mu = 0.011) allocation failure scavenge might not succeed


<--- JS stacktrace --->

==== JS stack trace =========================================

    0: ExitFrame [pc: 000001BDFE750361]
Security context: 0x03cfae81d9f1 <JSObject>
    1: /* anonymous */ [000003B954E99759] [D:\project\MyProjects\MyProject\node_modules\readdirp\stream-api.js:~37] [pc=000001BE00E89890](this=0x03b954e99569 <ReaddirpReadable map = 00000200F40F1511>)
    2: emit [000003CFAE845E51] [events.js:~140] [pc=000001BE00C23535](this=0x03b954e99569 <ReaddirpReadable map = 00000200F40F1511>,0x03b1a529c6d...

FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
 1: 00007FF61B8AABAA v8::internal::GCIdleTimeHandler::GCIdleTimeHandler+4810
 2: 00007FF61B850C96 uv_loop_fork+80486
 3: 00007FF61B851BC0 uv_loop_fork+84368
 4: 00007FF61BCCDC6E v8::internal::FatalProcessOutOfMemory+798
 5: 00007FF61BCCDBA7 v8::internal::FatalProcessOutOfMemory+599
 6: 00007FF61BFA6E24 v8::internal::Heap::RootIsImmortalImmovable+14788
 7: 00007FF61BF9CA64 v8::internal::Heap::CollectGarbage+7556
 8: 00007FF61BF9B138 v8::internal::Heap::CollectGarbage+1112
 9: 00007FF61BFA4AA7 v8::internal::Heap::RootIsImmortalImmovable+5703
10: 00007FF61BFA4B26 v8::internal::Heap::RootIsImmortalImmovable+5830
11: 00007FF61BB65611 v8::internal::Factory::NewFillerObject+49
12: 00007FF61C2C03DA v8::internal::StoreBuffer::StoreBufferOverflow+26826
13: 000001BDFE750361

主线是内存泄漏。

问题:什么会导致这种行为?哪里可以解决所有文件上的观察程序启动问题,尽管他们没有进行任何更改也没有保存文件?

gulp version: 4.0
node version: 8.11 and 11.2

0 个答案:

没有答案