{"__browser":{"country":"US","device":"unknown_device","mobile":false,"name":"unknown browser","platform":"unknown_platform","version":"0"},"__constants":{},"__CPDATA":{"domain_iframe":"https://cdpn.io","environment":"production","host":"codepen.io","iframe_allow":"accelerometer *; ambient-light-sensor *; camera *; display-capture *; encrypted-media *; geolocation *; gyroscope *; microphone *; midi *; payment *; vr *; web-share *; serial *; xr-spatial-tracking *","iframe_sandbox":"allow-downloads allow-forms allow-modals allow-pointer-lock allow-popups-to-escape-sandbox allow-popups allow-presentation allow-same-origin allow-scripts allow-top-navigation-by-user-activation"},"__graphql":{"data":{"data":{"sessionUser":{"id":"VoDkNZ","name":"Captain Anonymous","title":"Captain Anonymous","avatar":"https://assets.codepen.io/t-1/user-default-avatar.jpg?format=auto&version=0","currentContext":{"id":"VoDkNZ","title":"Captain Anonymous","name":"Captain Anonymous","avatar":"https://assets.codepen.io/t-1/user-default-avatar.jpg?format=auto&version=0","username":"anon","__typename":"User"},"currentTeamId":null,"username":"anon","admin":false,"anon":true,"pro":false,"verified":false,"featureFlags":[],"teams":[],"__typename":"User"}}},"url":"https://codepen.io/graphql","api":"cprails"},"__user":{"anon":true,"base_url":"/anon/","cohorts":[],"current_team_hashid":null,"current_team_id":0,"hashid":"VoDkNZ","id":1,"itemType":"user","name":"Captain Anonymous","paid":false,"tier":0,"username":"anon","created_at":null,"email_verified":null,"collections_count":0,"collections_private_count":0,"followers_count":0,"followings_count":0,"pens_count":0,"pens_private_count":0,"projects_count":0,"projects_private_count":0},"__firebase":{"config":{"apiKey":"AIzaSyBgLAe7N_MdFpuVofMkcQLGwwhUu5tuxls","authDomain":"codepen-store-production.firebaseapp.com","databaseURL":"https://codepen-store-production.firebaseio.com","disabled":false,"projectId":"codepen-store-production"},"token":"eyJhbGciOiJSUzI1NiJ9.eyJhdWQiOiJodHRwczovL2lkZW50aXR5dG9vbGtpdC5nb29nbGVhcGlzLmNvbS9nb29nbGUuaWRlbnRpdHkuaWRlbnRpdHl0b29sa2l0LnYxLklkZW50aXR5VG9vbGtpdCIsImNsYWltcyI6eyJvd25lcklkIjoiVm9Ea05aIiwiYWRtaW4iOmZhbHNlfSwiZXhwIjoxNzMzODgwNzIyLCJpYXQiOjE3MzM4NzcxMjIsImlzcyI6ImZpcmViYXNlLWFkbWluc2RrLThva3lsQGNvZGVwZW4tc3RvcmUtcHJvZHVjdGlvbi5pYW0uZ3NlcnZpY2VhY2NvdW50LmNvbSIsInN1YiI6ImZpcmViYXNlLWFkbWluc2RrLThva3lsQGNvZGVwZW4tc3RvcmUtcHJvZHVjdGlvbi5pYW0uZ3NlcnZpY2VhY2NvdW50LmNvbSIsInVpZCI6IlZvRGtOWiJ9.xHp_6z3SHEP1hxlX_4qBREUejjsH7mttoFXjJRz2yMWrU3YugYjuF_xFZjytg_GVi2LZmeFDR_7uA_uuCHb2wdu1awV4noXDBTSnljFjt4LniaAbztSa457SDKtweubQKihI5GDctHiLRpJcAp9X-bP4t0DrN-R3FcM_qFMupUGvapMYjT1SVXVrCU7GBYrJhHoHhplzjZ0oZrYyyTkN86mLxhS3wGPR72t9Z2_Gv4f8owxIAT9wQboMYnHXWCzKqs71yarCw6jDJMlHwSxiitQswNoJCTWEc9MNJ3zXP9N7Zh4XaCC4NLB8EXB7QtciSsL1--XDjOqykfjT9cwYng"},"__pay_stripe_public_key":"pk_live_2GndomDfiklqpSNQn8FrGuwZSMIMzha7DkLJqlYe7IR0ihKAlKdiHg68JJc5eVPt68rzAjzAAVXcUwjySHRCsgjQQ00gtRBUFNH","__pay_braintree_env":"production","__item":"{\"id\":73198558,\"user_id\":5928893,\"html\":\"<h1>Example 8<\\/h1>\\n\\n<h1>Example 8: Recording heap allocations<\\/h1>\\n\\n<p>Let's analyze the impact of closures on memory<\\/p>\\n\\n<p>You can see that 'eval' retains a reference on all the variables of the closure.<\\/p>\\n\\n<ol>\\n <li>Start to record heap allocations<\\/li>\\n\\n <li>Start the creation of new closures<\\/li>\\n\\n <li>Analyze what is happening<\\/li>\\n<\\/ol>\\n\\n<p><button onclick=\\\"largeClosures()\\\">Closures mantain hold on large string<\\/button><\\/p>\\n\\n<p><button onclick=\\\"smallClosures()\\\">Closures mantain hold only on small\\n strings<\\/button><\\/p>\\n\\n<p><button onclick=\\\"evalClosures()\\\">Closures with eval<\\/button><\\/p>\\n\\n<p><button onclick=\\\"stopAndClear()\\\">Stop and clear<\\/button><\\/p>\\n\\n<script>\\n 'use strict';\\n var intervalId,\\n closures = [];\\n\\n function createLargeClosure() {\\n var largeStr = new Array(1000000).join('x');\\n return function lC() {\\n return largeStr;\\n };\\n }\\n\\n function createSmallClosure() {\\n var smallStr = 'x';\\n var largeStr = new Array(1000000).join('x');\\n return function sC() {\\n return smallStr;\\n };\\n }\\n\\n function createEvalClosure() {\\n var smallStr = 'x';\\n var largeStr = new Array(1000000).join('x');\\n return function eC() {\\n eval('');\\n return smallStr;\\n };\\n }\\n\\n function largeClosures() {\\n stopInterval();\\n intervalId = setInterval(function() {\\n closures.push(createLargeClosure());\\n }, 1000);\\n }\\n\\n function smallClosures() {\\n stopInterval();\\n intervalId = setInterval(function() {\\n closures.push(createSmallClosure());\\n }, 1000);\\n }\\n\\n function evalClosures() {\\n stopInterval();\\n intervalId = setInterval(function() {\\n closures.push(createEvalClosure());\\n }, 1000);\\n }\\n\\n function stopInterval() {\\n if (intervalId) {\\n clearInterval(intervalId);\\n }\\n intervalId = null;\\n }\\n\\n function clear() {\\n closures.length = 0;\\n }\\n\\n function stopAndClear() {\\n stopInterval();\\n clear();\\n }\\n<\\/script>\\n\\n<hr>\\n<pre>\\n'use strict';\\n\\nvar intervalId,\\n closures = [];\\n \\nfunction createLargeClosure() {\\n var largeStr = new Array(1000000).join('x');\\n return function lC() {\\n return largeStr;\\n };\\n}\\n\\nfunction createSmallClosure() {\\n var smallStr = 'x';\\n var largeStr = new Array(1000000).join('x');\\n return function sC() {\\n return smallStr;\\n };\\n}\\n\\nfunction createEvalClosure() {\\n var smallStr = 'x';\\n var largeStr = new Array(1000000).join('x');\\n return function eC() {\\n eval('');\\n return smallStr;\\n };\\n}\\n\\nfunction largeClosures() {\\n stopInterval();\\n intervalId = setInterval(function () {\\n closures.push(createLargeClosure());\\n }, 1000);\\n}\\n\\nfunction smallClosures() {\\n stopInterval();\\n intervalId = setInterval(function () {\\n closures.push(createSmallClosure());\\n }, 1000);\\n \\n}\\n\\nfunction evalClosures() {\\n stopInterval();\\n intervalId = setInterval(function () {\\n closures.push(createEvalClosure());\\n }, 1000);\\n}\\n\\nfunction stopInterval() {\\n if (intervalId) {\\n clearInterval(intervalId);\\n }\\n intervalId = null;\\n}\\n\\nfunction clear() {\\n closures.length = 0;\\n}\\n\\nfunction stopAndClear(){\\n stopInterval();\\n clear();\\n}\\n<\\/pre>\",\"css\":\"\",\"js\":\"\",\"html_pre_processor\":\"none\",\"css_pre_processor\":\"none\",\"js_pre_processor\":\"none\",\"html_classes\":\"\",\"css_starter\":\"neither\",\"js_library\":null,\"created_at\":\"2024-02-09T14:33:33.643Z\",\"updated_at\":\"2024-02-09T14:34:20.245Z\",\"title\":\"Example 8\",\"description\":\"\",\"slug_hash\":\"bGZxZgV\",\"head\":\"\",\"private\":false,\"slug_hash_private\":\"60244e397da3814e60ca6db7d31b94c7\",\"has_animation\":true,\"team_id\":0,\"css_prefix\":\"neither\",\"template\":false,\"parent_id\":0,\"comments_count\":0,\"custom_screenshot_filename\":null,\"loves_count\":0,\"pick\":false,\"popularity_score\":0,\"views_count\":0,\"pick_visible_at\":null,\"cpid\":\"018d8e49-bccc-7eca-b078-3cc5e72c5295\",\"is_new_editor_pen\":false,\"protected\":false,\"access\":\"Public\",\"pen_hash\":null,\"hashid\":\"bGZxZgV\"}"}