By using a language that has a garbage collection mechanism, developers generally do not have to worry about memory management issues. However, the problem with JavaScript in memory management and collection is a bit different. One of the main problems is that the amount of available memory allocated to a Web browser is typically less than that allocated to a desktop application. The main purpose of this is to prevent the system from running out of all of the system memory and causing a crash of the Web page that runs JavaScript for security reasons. Memory throttling issues not only affect allocating memory to variables, but also affect the call stack and the number of statements that can be executed concurrently in one thread.
Therefore, make sure that you use the least amount of memory for better performance on your page. The best way to optimize memory consumption is to save only the necessary data for the code in execution. Once the data is no longer in use, it is best to release its reference by setting its value to null----This practice is called dereferencing. This practice applies to most global variables and properties of global objects. Local variables are automatically dereferenced when they leave the execution environment.
Eg:function Createperson (name) {
var localperson=new Object ();
Localperson.name=name;
return Localperson;
}
var Aa=createperson (June);
AA = null;//manual release of AA references
This pest for global variable AA requires that we manually dereference it when not using it.
However, releasing a reference to a value does not mean that the memory consumed by the value is automatically reclaimed. The real effect of dereferencing is to leave the value out of the execution environment so that it can be reclaimed the next time the garbage collector runs. This is today to understand the collation, hoping to help some friends.
Performance optimizations for JavaScript (reasonable management memory)