Memory leak in JavaScript (Chrome)

前端 未结 2 1516
情话喂你
情话喂你 2021-02-03 12:34

I\'m calling a function 50 times a second, which does some expensive things as it is painting alot on a element.

It works great, no problems

2条回答
  •  闹比i
    闹比i (楼主)
    2021-02-03 13:36

    Look at heap profile under the Profiles tab in Chrome's developer tools for information about memory usage.

    You can do the following to prevent memory leaks:

    • Test your code with JSLint, to see if that will give you some pointers.
    • Use the var keyword to give your variables function scope, so they can be garbage collected when they go out of scope. Without the var keyword variables have global scope.
    • Use delete variable; statements to remove the object as well as the reference from memory. Setting the variable to null will only remove the object from memory, but not its reference.

提交回复
热议问题