Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2e05cf1

Browse files
joyeecheungrichardlau
authored andcommitted
module: fix leak of vm.SyntheticModule
Previously we maintain a strong persistent reference to theModuleWrap to retrieve the ID-to-ModuleWrap mapping fromthe HostImportModuleDynamicallyCallback using the number IDstored in the host-defined options. As a result the ModuleWrapwould be kept alive until the Environment is shut down, whichwould be a leak for user code. With the new symbol-basedhost-defined option we can just get the ModuleWrap from theJS-land WeakMap so there's now no need to maintain thisstrong reference. This would at least fix the leak forvm.SyntheticModule. vm.SourceTextModule is still leakingdue to the strong persistent reference to the v8::Module.PR-URL:#48510Backport-PR-URL:#51004Refs:#44211Refs:#42080Refs:#47096Refs:#43205Refs:#38695Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
1 parenta86a2e1 commit2e05cf1

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

‎src/module_wrap.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ ModuleWrap::ModuleWrap(Environment* env,
6464
if (!synthetic_evaluation_step->IsUndefined()) {
6565
synthetic_ =true;
6666
}
67+
MakeWeak();
6768
}
6869

6970
ModuleWrap::~ModuleWrap() {
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Flags: --experimental-vm-modules --max-old-space-size=16
2+
'use strict';
3+
4+
// This tests that vm.SyntheticModule does not leak.
5+
// See https://github.com/nodejs/node/issues/44211
6+
require('../common');
7+
constvm=require('vm');
8+
9+
letcount=0;
10+
asyncfunctioncreateModule(){
11+
// Try to reach the maximum old space size.
12+
constm=newvm.SyntheticModule(['bar'],()=>{
13+
m.setExport('bar',newArray(512).fill('----'));
14+
});
15+
awaitm.link(()=>{});
16+
awaitm.evaluate();
17+
if(count++<4*1024){
18+
setTimeout(createModule,1);
19+
}
20+
returnm;
21+
}
22+
23+
createModule();

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp