Last active
October 15, 2020 01:28
-
-
Save lucas-silveira/82cc02a45fea95d026c232b2ffd2ddb7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var theThing = null; | |
| var replaceThing = function() { | |
| var originalThing = theThing; | |
| // Define um encerramento que faz referência a originalThing, mas nunca | |
| // é realmente chamado. Mas, como esse encerramento existe, | |
| // originalThing estará no ambiente léxico para todos | |
| // os encerramentos definidos em replaceThing, em vez de ser otimizado | |
| // a partir dele. Se você remover esta função, não haverá vazamento. | |
| var unused = function() { | |
| if (originalThing) | |
| console.log("hi"); | |
| }; | |
| theThing = { | |
| longStr: new Array(1000000).join('*'), | |
| // Embora originalThing seja teoricamente acessível por esta | |
| // função, obviamente não a usa. Mas porque | |
| // originalThing faz parte do ambiente léxico, someMethod | |
| // manterá uma referência a originalThing e, portanto, mesmo que | |
| // estejamos substituindo theThing por algo que não tem | |
| // uma maneira eficaz de fazer referência ao valor antigo de theThing, o valor antigo | |
| // nunca será limpo! | |
| someMethod: função() {} | |
| }; | |
| originalThing = null | |
| }; | |
| setInterval(replaceThing, 1000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment