@@ -302,82 +302,6 @@ console.log(globalVar);
302302// 1000
303303```
304304
305- ## ` vm.measureMemory([options]) `
306-
307- <!-- YAML
308- added: v13.10.0
309- -->
310-
311- > Stability: 1 - Experimental
312-
313- Measure the memory known to V8 and used by all contexts known to the
314- current V8 isolate, or the main context.
315-
316- * ` options ` {Object} Optional.
317- * ` mode ` {string} Either ` 'summary' ` or ` 'detailed' ` . In summary mode,
318- only the memory measured for the main context will be returned. In
319- detailed mode, the measure measured for all contexts known to the
320- current V8 isolate will be returned.
321- ** Default:** ` 'summary' `
322- * ` execution ` {string} Either ` 'default' ` or ` 'eager' ` . With default
323- execution, the promise will not resolve until after the next scheduled
324- garbage collection starts, which may take a while (or never if the program
325- exits before the next GC). With eager execution, the GC will be started
326- right away to measure the memory.
327- ** Default:** ` 'default' `
328- * Returns: {Promise} If the memory is successfully measured the promise will
329- resolve with an object containing information about the memory usage.
330-
331- The format of the object that the returned Promise may resolve with is
332- specific to the V8 engine and may change from one version of V8 to the next.
333-
334- The returned result is different from the statistics returned by
335- ` v8.getHeapSpaceStatistics() ` in that ` vm.measureMemory() ` measure the
336- memory reachable by each V8 specific contexts in the current instance of
337- the V8 engine, while the result of ` v8.getHeapSpaceStatistics() ` measure
338- the memory occupied by each heap space in the current V8 instance.
339-
340- ``` js
341- const vm = require (' vm' );
342- // Measure the memory used by the main context.
343- vm .measureMemory ({ mode: ' summary' })
344- // This is the same as vm.measureMemory()
345- .then ((result ) => {
346- // The current format is:
347- // {
348- // total: {
349- // jsMemoryEstimate: 2418479, jsMemoryRange: [ 2418479, 2745799 ]
350- // }
351- // }
352- console .log (result);
353- });
354-
355- const context = vm .createContext ({ a: 1 });
356- vm .measureMemory ({ mode: ' detailed' , execution: ' eager' })
357- .then ((result ) => {
358- // Reference the context here so that it won't be GC'ed
359- // until the measurement is complete.
360- console .log (context .a );
361- // {
362- // total: {
363- // jsMemoryEstimate: 2574732,
364- // jsMemoryRange: [ 2574732, 2904372 ]
365- // },
366- // current: {
367- // jsMemoryEstimate: 2438996,
368- // jsMemoryRange: [ 2438996, 2768636 ]
369- // },
370- // other: [
371- // {
372- // jsMemoryEstimate: 135736,
373- // jsMemoryRange: [ 135736, 465376 ]
374- // }
375- // ]
376- // }
377- console .log (result);
378- });
379- ```
380-
381305## Class: ` vm.Module `
382306<!-- YAML
383307added:
@@ -1064,6 +988,82 @@ added: v0.11.7
1064988Returns `true` if the given `object` object has been [contextified][] using
1065989[`vm.createContext()`][].
1066990
991+ ## `vm.measureMemory([options])`
992+
993+ <!-- YAML
994+ added: v13.10.0
995+ -->
996+
997+ > Stability: 1 - Experimental
998+
999+ Measure the memory known to V8 and used by all contexts known to the
1000+ current V8 isolate, or the main context.
1001+
1002+ * `options` {Object} Optional.
1003+ * `mode` {string} Either `' summary' ` or `' detailed' `. In summary mode,
1004+ only the memory measured for the main context will be returned. In
1005+ detailed mode, the measure measured for all contexts known to the
1006+ current V8 isolate will be returned.
1007+ **Default:** `' summary' `
1008+ * `execution` {string} Either `' default' ` or `' eager' `. With default
1009+ execution, the promise will not resolve until after the next scheduled
1010+ garbage collection starts, which may take a while (or never if the program
1011+ exits before the next GC). With eager execution, the GC will be started
1012+ right away to measure the memory.
1013+ **Default:** `' default' `
1014+ * Returns: {Promise} If the memory is successfully measured the promise will
1015+ resolve with an object containing information about the memory usage.
1016+
1017+ The format of the object that the returned Promise may resolve with is
1018+ specific to the V8 engine and may change from one version of V8 to the next.
1019+
1020+ The returned result is different from the statistics returned by
1021+ `v8.getHeapSpaceStatistics()` in that `vm.measureMemory()` measure the
1022+ memory reachable by each V8 specific contexts in the current instance of
1023+ the V8 engine, while the result of `v8.getHeapSpaceStatistics()` measure
1024+ the memory occupied by each heap space in the current V8 instance.
1025+
1026+ ```js
1027+ const vm = require(' vm' );
1028+ // Measure the memory used by the main context.
1029+ vm.measureMemory({ mode: ' summary' })
1030+ // This is the same as vm.measureMemory()
1031+ .then((result) => {
1032+ // The current format is:
1033+ // {
1034+ // total: {
1035+ // jsMemoryEstimate: 2418479, jsMemoryRange: [ 2418479, 2745799 ]
1036+ // }
1037+ // }
1038+ console.log(result);
1039+ });
1040+
1041+ const context = vm.createContext({ a: 1 });
1042+ vm.measureMemory({ mode: ' detailed' , execution: ' eager' })
1043+ .then((result) => {
1044+ // Reference the context here so that it won' t be GC ' ed
1045+ // until the measurement is complete.
1046+ console.log(context.a);
1047+ // {
1048+ // total: {
1049+ // jsMemoryEstimate: 2574732,
1050+ // jsMemoryRange: [ 2574732, 2904372 ]
1051+ // },
1052+ // current: {
1053+ // jsMemoryEstimate: 2438996,
1054+ // jsMemoryRange: [ 2438996, 2768636 ]
1055+ // },
1056+ // other: [
1057+ // {
1058+ // jsMemoryEstimate: 135736,
1059+ // jsMemoryRange: [ 135736, 465376 ]
1060+ // }
1061+ // ]
1062+ // }
1063+ console.log(result);
1064+ });
1065+ ```
1066+
10671067## `vm.runInContext(code, contextifiedObject[, options])`
10681068<!-- YAML
10691069added: v0.3.1
0 commit comments