Web site causes the browser to crash

Source: Internet
Author: User
Tags count garbage collection

When interviewing a company, the interviewer asks, what causes the browser to crash? Fools, only to answer the memory leak. In fact, the Web page in the process of loading, often for a variety of reasons to make the browser's reflection slow, or caused the browser to lose its response, and even cause the machine can not do other operations.

For visitors, if you log on to your site, the browser immediately crashes, I think this is intolerable to anyone, summed up the site caused the browser crash reasons:

1. Memory leaks

Or to talk about the memory leak, the Web site due to memory leaks and crashed into two situations, the server crash and browser crash. The problem with a memory leak is obvious, and it causes a reference to the allocated memory to be lost, and the process uses that memory as long as the system is still running. As a result, programs that used to consume more memory degrade system performance until the machine completely stops working to completely empty the memory.

Apache Web server is written in C/s + +, the memory leak problem of C + + is needless to say, there is no memory in the system can not be recycled, sometimes resulting in low memory or system crashes. In Java, a memory leak is a collection of objects that are allocated that are not recoverable by GC, but which occupy memory.

On the client side, the memory leaks caused by JavaScript can also cause the browser to crash. Articles about memory leaks from JavaScript, the more authoritative are "Memory leak patterns in JavaScript" and "Understanding and solving Internet Explorer leak pattern S ".

JavaScript is a garbage collection (garbage collector,gc) language, which means that memory is assigned to an object based on its creation and is retracted by the browser when there is no reference to the object. Again, according to the article "Fabulous Adventures in Coding", "JScript uses a nongenerational mark-and-sweep garbage." Nongenerational Mark-and-sweep "It can be understood that browsers handle JavaScript not with pure garbage collection, but also use reference counting to process memory for native objects such as Dom, ActiveX object.

In the reference counting system, each referenced object retains a count to learn how many objects are referencing it. If the count is zero, the object is destroyed and the memory it occupies is returned to the heap. When objects refer to each other, they form circular references, and browsers (ie6,firefox2.0) can be handled correctly for circular references between pure JavaScript objects, but because in the reference counting system, objects referenced by each other cannot be destroyed because the reference count can never be zero. Therefore, the browser cannot handle a circular reference between JavaScript and a native object, such as DOM, ActiveX object. So, when we have a circular reference between a native object and a JavaScript object, there is a memory leak problem.

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.