Understanding and solving IE Memory leakage [Translation 4]

Source: Internet
Author: User
Tags blank page management studio

This is a very busy time, but I finally successfully submitted an important feature of the product, Enterprise Overall Dashboard. I will introduce it if I have time. Although this IE Memory leakage is getting more and more depressing, it is still because of the need to have a good start and end, so I have finished the last section. This is also a complete series.

Pseudo-Leaks)

In most cases, the actual behaviors of Some APIs and their expected behaviors may lead to incorrect memory leakage judgment. It seems that most of the leaks always occur in the dynamic script operations on the same page, but it is rare to jump from a page to a blank page. Then how can you eliminate this problem like eliminating inter-page leaks, and whether the memory usage in the running of the new task is what you expect. We will use the rewriting of script text as an example that seems to be leaked.

As with the DOM insertion sequence, this problem also requires the creation of temporary objects to generate "leakage ". By repeatedly rewriting the script text inside a script element object, you will gradually leak various Script Engine objects that have been associated with the covered content. In particular, objects related to script debugging are preserved as full code objects.

<Html>
<Head>
<Script language = "JScript">
Function LeakMemory ()
{
// Do it a lot, look at Task Manager for memory response
For (I = 0; I <5000; I ++)
{
HostElement. text = "function foo (){}";
}
}
</Script>
</Head>
<Body>
<Button onclick = "LeakMemory ()"> Memory Leaking Insert </button>
<Script id = "hostElement"> function foo () {}</script>
</Body>
</Html>

If you run the sample code above and use the task manager to view the Code, when you jump to a blank page from the "leak" page, you will not notice any script leakage. Because this script leak occurs completely inside the page, and the memory used when you leave the page will be recycled. This is a bad situation for the behavior we originally expected. You want to completely remove the original script object from the page after overwriting the script content. But in fact, because the overwritten script object may have been used as an event handler, and there may be some uncleared reference counts. As you can see, this is a leakage. On the surface, memory consumption may seem terrible, but this is completely acceptable.

Summary

Every Web developer may have a list of their own sample code. When they see the code in the code list, they will be aware of the leakage and will use some development skills to avoid these problems. This method is simple and convenient, but it is also a common cause of Memory leakage on Web pages today. Consider the leak scenarios we are discussing instead of focusing on independent code examples. You will use more effective policies to solve the leakage problem. This concept will enable you to estimate problems in the design phase and ensure that you have plans to deal with potential leaks. Use the habit of writing reinforcement code (Translator's note: it is the code for exception handling or object cleanup) and clean up all the memory occupied by yourself. Although it may be too exaggerated for this problem, you may have barely seen the situation where you need to clean up the memory occupied by writing scripts. What makes this problem more and more obvious is that, potential leakage between script variables and expando attributes.

If you are interested in patterns and designs, I strongly recommend Scott's blog because it demonstrates a general example of removing closure-based leakage code. Of course, this requires more code, but this practice is effective, and the improved scenario is very easy to locate and debug in the code. Similar injection designs can also be used in loop references caused by expando properties. However, you must note that the registered method itself should not let the leak (especially where the closure is used) run away.

About the author

Justin Rogers recently joined the Internet Explorer team as an Object Model developer working on extensibility and previusly worked on such notable projects as. NET QuickStart Tutorials ,. NET Terrarium, and SQL Reporting Services Management Studio in SQL Server 2005.

[Full text] Note: This translation is not authorized by the author, and you are solely responsible for any reprint.

This series of articles: 1, 2, and 3.

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.