Summary of Causes of web browser crashes (multiple browsers)

Source: Internet
Author: User
Tags response code

When interviewing a company, the interviewer asks, cause the browser to crashWhat are the reasons for this? Foolish generation, only answer the memory leak. Actually in Web pageIn the process of loading, often for various reasons the browser's reflection is slow, or cause the browser to lose response, and even cause the machine can not do other operations.

For visitors, if you log in 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

Let's talk about a memory leak, a crash of a Web site due to a memory leak, a crash of the server and a crash of the browser. The problem with a memory leak is obvious, and it causes the reference to the allocated memory to be lost, and the process will use that memory as long as the system is still running. As a result, programs that have used up more memory will degrade system performance until the machine completely stops working before it completely empties the memory.

Apache's Web server is written in C/s + +, and the memory leak problem in C/s + + has no need to say that there is not enough memory in the system, which can sometimes cause memory shortage or system crash. In Java, a memory leak is the existence of some allocated, useless objects that are not reclaimed by the GC, but that consume memory.

And on the client side, JavaScript causes a memory leak that could also cause the browser to crash. The more authoritative articles about memory leaks in JavaScript are "memory leak patterns in JavaScript" and "Understanding and solving Internet Explorer leak Patterns ".

JavaScript is a garbage-collected (garbage COLLECTOR,GC) language, which means that memory is assigned to the object based on the creation of the object 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 collector." Nongenerational Mark-and-sweep "can be understood that browser processing JavaScript is not purely garbage collected, but also uses reference counting to handle 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 consumes is returned to the heap. When objects refer to each other, they form a circular reference, the browser (IE6, Firefox2.0) The circular reference between pure JavaScript objects can be handled correctly, but because the reference counting system cannot be destroyed because the reference count is never zero, the browser cannot process JavaScript and the native object ( For example, the DOM, ActiveX Object) is a circular reference. Therefore, a memory leak occurs when we have a circular reference between the native object and the JavaScript object.

Simply put, the browser uses reference counting to handle memory for the native object, and the reference count object cannot be destroyed, and a circular reference involving the native object will have a memory leak. With the following example, to understand this sentence, you can basically understand the memory leaks caused by JavaScript.

The code is as follows:
varfunction//Obj=document.getelementbyid ("DivElement");  //   document.getElementById ("DivElement"). expandoproperty=

Visible, a circular reference is generated between the JavaScript object and the DOM object. Because DOM objects are managed by reference counting, none of the two objects will be destroyed.

Another situation is that in closures, when a closure is encountered, we can easily create a closure Memory Leak when we bind an event response code to the native object. The key reason is the same as the former, and is also a circular reference across JavaScript objects and native objects. Just the code is more subtle.

The code is as follows:
function attachevents (Element) {  //   element.attachevent ("onclick"function  ////

Here's a simple explanation of why JavaScript causes memory leaks, and memory leaks increase the burden on the browser, which is likely cause the browser to crash, all we have to do is try to avoid this situation by referring to just the Memory leak patterns in JavaScript and the understanding and solving Internet Explorer leak Patterns "two articles to understand. The ultimate goal of handling JavaScript memory leaks is to break the circular references between JavaScript objects and native objects, or to clear 0 reference counts, releasing objects.

Some memory leaks, such as a closed memory leak, may be more difficult to detect, and we may refer to the JavaScript memory leak tool for use in memory leaks.

2. Web page code complexity and browser bugs

The emergence of a large number of personal sites and low-quality site code is generally not supported by the browsing standards, if it happens to some bugs in the browser, the browser rendering engine in the processing of these Web page code errors, such as into a dead loop or a direct crash.

HTML code causes Web site to crash

This is an HTML structure error that causes IE6 to crash, and adding any characters before or after <col width= "/>" will result in IE6 Crash.

The code is as follows:
<!DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd "> <HTML> <Head></Head> <Body>    <Table> <TR> <TD> <Table> <Colgroup><Colwidth= "100px"><Col></Colgroup> </Table> </TD> </TR> <Table> </Body> </HTML> 

The code to a Korean web site, regardless of the use of XHTML or HTML version, as long as with the DOCTYPE declaration, IE6 will immediately crash, when no DOCTYPE declaration, there is no error, the reason may be related to the document type declaration.

CSS code that makes IE6 crash

The code is referenced from the website cats who code. The bug was found with 2007, which is said to be discovered by a Japanese:

The code is as follows:
< style > * {position:relative} </ style > < Table >< input ></ Table >

The reason is that the contents are placed directly in the table, the browser is closed when IE6 causes Mshtml.dll module corruption, and non-IE6 is safe.

In addition, the bug that exists in IE6 also has the following situation, when the pseudo-class is a:active, you also encounter this problem:
The code is as follows:
<styletype= "Text/css">a{position:relative;}a:hover{float: Left;} </style> <ahref="">Crash IE6, Crash IE6</a> 

Solution: Add zoom:1 for <a>; Trigger the Haslayout.

The code is as follows:
<styletype= "Text/css">a{position:relative;Zoom:1;}a:hover{float: Left;} </style> 

CSS code that makes IE7 crash

This bug comes from stealing rice, which only exists in IE7, which is estimated to be handling ellipsis, causing IE7 to crash.

The code is as follows:
<style type= "text/css" > div {float:left; width:175px;} ul {overflow:hidden; white-space:nowrap; text-overflow:ellipsis;} Li {position:relative;}
<Div> <ul> <Li>Crash crash crash crash crash crash IE7</Li> <Li>Crash crash crash crash crash crash IE7</Li> </ul> </Div> 

Solution: Add zoom:1 for <li>; Make it trigger Haslayout

JavaScript code that makes IE6 crash

From Internet Explorer Sucks, this site uses code, and when you use IE6 access, the browser crashes immediately. The code is as follows:

The code is as follows:
< Script >  for   in document.write) {document.write (x);} </ Script >

The causes are not resolved for the time being, but are generally not written in terms of compatibility and execution efficiency.

3. Too much web data

  Web pages contain a large number of data to be processed, causing the system to be busy, such as multi-image pages, extra-long pages, or the various controls embedded in the Web page can cause the browser to process large amounts of data, causing the system to be busy such as flash games, ActiveX controls, and so on. When the browser visits the website, if the data volume of the website is large, it will make the browser generally consume a lot of CPU usage and memory, cause the browser to lose the response, and even crash the computer system. When it comes to web development, the problem can be largely avoided if you take full account of the performance of your website.

4. AJAX Web Service Vulnerabilities

Ajax is an XML-based asynchronous transmission, the text format of the XML message may be the amount of binary data bandwidth of more than twice times. The more bandwidth is required to transmit an XML message, the less resources are available for the system or application to perform other tasks. For example, perform complex algorithms to obtain desired results.

Excessive bandwidth can cause performance degradation caused by overloading the system. Excessive bandwidth will cause the AJAX application to output broken data because there is not enough resources to generate clean data. This means that Web service portals (which are part of AJAX applications) will expose broken data to other parts of the portal, leading to malformed messages and over-parsing. If the threat exploited this vulnerability, it would cause the browser to crash.

On the other hand, frequent, smaller HTTP requests can add to the burden on the backend servers, load balancer, and firewalls, resulting in excessive bandwidth, resulting in degraded performance. If the client stays on the page for a long time or does not close the browser, the browser's memory will continue to rise, not released, causing the client browser to crash.

For this reason, when it comes to Ajax, we need to consider accelerating AJAX applications through specialized hardware accelerators, optimizing software, eliminating code redundancy, XML acceleration, and solving interoperability problems. In addition, actively monitoring traffic flows can continuously measure the network traffic performance of AJAX applications. By putting data into real-time logs, you can see where a large number of packet loss and jitter events occur, why the response is slow, and how to improve traffic performance by modifying the priority of the application.

5. Other reasons

In addition to the reasons mentioned above, there are many other reasons, although some will not cause the browser to crash directly, but also cause the site can not be accessed, such as log files resulting in disk full, Web server C pointer error, process lack of file descriptors, thread deadlock, temporary tables in the database is not enough and server overloading, etc., can refer to the Seven of the most common causes of web site crashes.

Summarize

For visitors, if you log in to your website, the browser immediately crashes, I think this is intolerable to anyone, by summarizing the "Web browser crash reasons", when we engage in web development and maintenance, we should try to avoid memory leaks, code errors and redundancy and excessive data, and so on, to build a better performance of the site.

PS: This article from http://www.169it.com/blog_article/3682342070.html from the summary, if reproduced please indicate the source

Summary of Causes of web browser crashes (multiple browsers)

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.