You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The problem is that this code does not create large closures anymore.
On modern versions of V8 the code var largeStr = new Array(1000000).join('x') creates a string of type CONS_ONE_BYTE_STRING_TYPE, which takes only about 600 bytes in memory (concatenation of concatenations of concatenations etc. of a single small string chunk like 'xxxxxxxx') instead of desired million bytes. In order to create really large closure you should use one of methods on string, which convert string into its plain form ONE_BYTE_STRING_TYPE. Right now some of those methods are indexOf('something'), slice(1), substring(1), toLowerCase() (situation may change with the next versions of V8).
The large memory leak example should look like
functioncreateLargeClosure(){varlargeStr='x'.repeat(1000000).toLowerCase();// ONE_BYTE_STRING_TYPE, takes 1000012 bytes on my machinevarlC=function(){returnlargeStr;};returnlC;}
Documentation page https://learn.microsoft.com/en-us/microsoft-edge/devtools-guide-chromium/memory-problems/heap-snapshots has a few examples of memory leaks:
The code to demonstrate easily detectable memory leak looks like
The problem is that this code does not create large closures anymore.
On modern versions of V8 the code
var largeStr = new Array(1000000).join('x')
creates a string of typeCONS_ONE_BYTE_STRING_TYPE
, which takes only about 600 bytes in memory (concatenation of concatenations of concatenations etc. of a single small string chunk like 'xxxxxxxx') instead of desired million bytes. In order to create really large closure you should use one of methods on string, which convert string into its plain formONE_BYTE_STRING_TYPE
. Right now some of those methods areindexOf('something')
,slice(1)
,substring(1)
,toLowerCase()
(situation may change with the next versions of V8).The large memory leak example should look like
Also don't forget to fix similar code on the example page https://microsoftedge.github.io/Demos/devtools-memory-heap-snapshot/example-07.html.
Document Details
⚠ Do not edit this section. It is required for learn.microsoft.com ➟ GitHub issue linking.
AB#46865090
The text was updated successfully, but these errors were encountered: