Analysis of memory release methods in JS class library Bindows1.3

Source: Internet
Author: User

I introduced the JavaScript script Memory Leak in IE some time ago. Later, some enthusiastic netizens discussed the fact and principle of Memory leakage. In a small-scale test case, it was basically achieved to avoid the ML problem of scripts in IE. However, it seems very difficult to prevent the script ML in IE by taking "careful" measures recently. Is there an error in the discussion at the beginning?

What is "careful? That is to say, when objects are referenced by each other, when objects are discarded (not necessarily page refresh), each other's reference chain is broken, especially the reference between the objects created in the script and the objects in DHTML; clear all custom attributes in HTML elements, clear event handler callbacks in all HTML elements, and try to delete internal elements when the array is discarded.

The most important thing is to try not to create redundant Script objects and DHTML element objects. You can modify attributes to achieve the effect. Even if you have trouble, you will not re-create new objects.

After the preceding steps, the memory usage growth rate of IE decreases. However, it still cannot fully support complex script running (close to the complexity of Bindows), as reflected in the following points:
1. During script execution, the memory usage is still a process of increasing or decreasing;
2. Force IE to perform GC by minimizing the IE window. Only physical memory can be GC, which is invalid for virtual memory;
3. page skipping (URL change) the original script execution domain, and the memory volume is too small or even not released;
4. You must close the IEXPLORE. EXE process (that is, all IE Windows) to completely release the memory used by IE.

Today, I suddenly thought of Bindows, which had been a long-time violation. I ran to check that a February version was released at the end of 1.3, so I started running the demo on the home page. Needless to say, you just need to take a look, and the efficiency is quite high. In the demo, there is a GRID similar to multi-dimensional data display, and the headers of rows and columns are fixed. Hyun is already a constant feature of bindows. Before getting lost, I think we should look at how Bindows handles the memory? I really don't know. I was shocked!

Open www.bindows.net, I use IE memory (28PM + 18VM) M, open its demo program. The memory is up to (38PM + 35VM) M, and a few more operations are performed. The memory is up to (80PM + 75VM) M. So I closed the demo window, and IE released about 15 MB of memory, and stopped at the (70PM + 70VM) M level. I changed the URL of IE and jumped to google, the memory usage of IE does not seem to be reduced @_@. Haha, Bindows also has Memory Leak ~. It's really easy to understand. 555... after a short period of time, I can see that the memory usage of IE is almost the same as that when I started IE :). The real good news seems that I can no longer blame IE, so I began to trace the processing code of Bindows in onunload.

How can I jump to the onunload code? Here is an hack. press Alt + V, u, and B on IE (you need to disable script debugging in the uncheck IE options advanced, and the U shortcut key option is available in the menu View ). Close the demo dome window of Bindows immediately, select VS. NET 2003 as the Script debugger, and then directly jump to the onunload entrance.

In managing the script memory usage in IE, Bindows is very thoughtful. Complex objects all implement a complete dispose method. What is used?When called, the reference chains of the DHTML Object instance and the script object instance are cut off first. The data in the global cache variable is cleared and the delete keyword is used. The event handler function imported using attachEvent is used, detach is required. Other event processing Callbacks are cleared by null. parent or child link reference chains between Script objects are cut off.

It is a bit confusing here that the GC trigger of IE is uncertain (currently we know that the final trigger is to minimize the IE window), that is, you have done the above work well, when your page is just loaded, the memory will not be released immediately. However, after a period of use, the memory used by IE will be reduced. Therefore, you do not need to doubt the methods discussed previously, except for the "Disconnect the parent or child link reference chain between Script objects, the principles and handling methods of Bindows dispose are basically the same as discussed earlier.

Note: PM physical memory and VM Virtual Memory. Can be viewed in the task manager.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.