Release memory, batch loading problems and other issues in JScript

Source: Internet
Author: User
Release memory in JScript, batch loading problems, and other release dates: 1/24/2005 | updated on: 1/24/2005

Edit Nancy Michell

Q: I have some questions about garbage collection in JScript. I think there is a memory leak in Microsoft Internet Explorer 6.0, but on the other hand, it may be a circular reference problem. In my code, I assume that "new object ()" belongs to JScript and "document. createelement" belongs to Internet Explorer Dom. Therefore, the garbage collector in JScript cannot release DOM elements. Is this correct? What is the best way to avoid this problem?

When you load the code to Internet Explorer 6.0 and click "refresh", you can observe the increase in memory in "Task Manager:

A: This is not a memory leak. You are creating new text one thousand times on the page! This will increase the page. If you create many objects that cannot be obtained or released, the memory leakage occurs. Here, you will create many elements. Internet Explorer needs to save them to correctly render the page. Internet Explorer does not know that you will not run scripts that manipulate all these objects you just created in the future.

Memory is released when the page disappears (when you browse and exit the browser. It will not leak. When a page is destroyed, cyclic reference is interrupted.

Q: I tried to import some XML into the database by passing the XML to the stored procedure called by the ADO. Net SQL provider. When the XML file is too large, it will fail due to sqlexception exception (indicating a serious error. I failed to trace sp_xml_preparedocument.

It works well when using an XML file with 43403 characters, but if I add another character (by changing the last vendor field from "micros" to "microso "), it will fail. The parameters passed to the stored procedure are of the ntext type. I cannot use batch loading. Is this a known issue? Is the size limit from ADO. net, SQL, or sp_xml_preparedocument? Finally, is there a solution?

A: Actually, one way to load data in batches is to load the data into a segmentation table and then perform insert and update operations there. This problem occurs until sp_xml_preparedocument fails. Most of them are due to one of the following reasons: a single error character (or a character in the error code) causes the analyzer to fail; The nvarchar of the truncated XML is used; or use text to replace ntext (leading to invalid characters ).

Although there is a glimmer of hope, none is the actual cause of the problem, so the next step you should take is to try the latest SQL Server Service Pack (http://www.microsoft.com/ SQL ), the purpose is to see if this can correct the problem.

Q: I want to design a search interface and change the word "go ". Many websites use the "go" in various languages to indicate the submission function. But should I use words or some type of icons? Can I only use arrow icons?

A: Arrows, similar to the arrows shown in figure 1, all have direction. Therefore, their explanations depend on their positions. Text has no direction, so it has nothing to do with where you decide to place it; and the meaning will not change.

Figure 1 arrow icon

However, research shows that self-reported users prefer a button instead of other content, which is not more important than understanding the interface when they first met. This is true for tools or Web services that are used by chance.

No matter what tag you select for the submit button, remember that it is very important to support the Enter key as the search and query submit option. Users seldom comment on the enter function. Unless you do not have it, you will hear the comment! In addition, for availability purposes, the submit button illustration should be as close as possible to the submit button of the search text box (preferably on the right of it ).

Q: I have a question about maintaining the data tree structure of the SQL database and making the tree searchable and faster. XML can represent this structure, and I can use SQL for storage, but I want to quickly search the data tree. Unfortunately, the tree has many branches and leaves, which are very similar to the directory structure in the file system, so I cannot use a fixed table relationship. What is the best way to build the database structure?

A: SQLXML seems to be better executed at a lower level than at a deeper level. As XML nesting increases, the memory usage and processing time also increase. Read the following article about how to process hierarchies in SQL: Expanding hierarchies.

The deeper the XML nesting, the higher the overhead it needs to analyze or construct (from the plane data. Try to use the world's fastest XML analyzer to analyze XML in the range of 1,000-10,000 levels. Try to run a simple XSLT script for the same data. At a deeper level, there is almost always more overhead than at a lower level.

When XML is retrieved through XPath, SQLXML uses the SQL Server for XML explicit mode, which basically requires an ordered external Union. According to research from various industries, when constructing XML from flat-level relational data, the ordered external joint method is generally better than the hybrid fragment (Adaptive determination of the data granularity, otherwise, adjust it to avoid unnecessary union. SQLXML does not control or modify the layout of user data. Therefore, the adaptive storage policy is not an option.

When you use Updategram to modify XML, SQLXML will cut data (change it from layered format to flat format) and generate atomic DML statements, as in your example. When XML is inserted through batch loading, SQLXML will cut data again, but the SQL batch loading operation is used. Both are very effective.

The worst case for retrieval is to roughly obtain an option for each element type (rather than each element) and combine all options, then sort by nested primary key columns. Generally, this method causes two major performance problems. First, SQL server does not optimize the primary key columns (you should use many SQL: ype/XSD: Type delimiters in the annotated architecture, in this way, SQL XML can exclude unnecessary computations from the queries it generates ). Second, the ordered external Union range exceeds (for example,) Hundreds of element types.

The example you reference is not a horizontal comparison because it does not generate xml. It is easy to generate flat data that represents a hierarchy. The overhead part converts the flat representation to the real hierarchical representation (XML ). The deeper the hierarchy, the larger the overhead required for transformation. If you run the performance analysis tool on SQLXML, you will see that most of the processing time is occupied by the data type conversion in oledb and the conversion from the flat row set to the XML hierarchy, instead of spending on executing SQL queries. Finally, you can try to run a joint query without for XML explicit and verify that the SQL query is not a bottleneck.

If you choose to use XML to maintain the data tree structure, you should consider using sqlxml3.0 to cut this document into an SQL Server database. One possible solution is to create an annotated XSD architecture that describes the instance XML document. The maximum depth annotation allows you to describe the recursive tree structure. The SQLXML batch loading function allows you to cut this document into an SQL Server database. The SQLXML help file contains some examples. See the maximum depth section, which describes how to process XML documents of different levels (as long as they are recursive and you can specify the maximum number of levels ).

Q: I have noticed that many websites that require logon to access certain content or services do not directly put the logon box on the home page. Most websites contain a logon link somewhere on the top of the home page, or even do not place a link on the home page at all, but when the user browses the part of the site to be logged on, directs the user to the logon page.

Should the website directly display the logon section where users can enter their usernames and passwords on the homepage? Or is a small logon link enough? Or, the third option is better, that is, the user is prompted to log on only when the user needs to log on?

A: In some cases, it may be appropriate to provide the user name and password fields on all pages, instead of placing the user name and password request fields on the home page or on a separate page dedicated to logon. This does occupy some screen space, but it can remind unregistered users that they will get more information if they log on. Bringing users to a dedicated logon screen can confuse users, especially when you return them to their own page.

Q: Suppose you have a function, which is sometimes in try ...... Catch ...... Internal, but not in other cases. Suppose that when it is in try catch, I intend to trigger the same error again, but when it is not in it, I do not intend to do this, as a result, I will get an error-"an exception has been thrown but not captured ".

Therefore, I want to re-raise this error only when a nested catch captures it. Is there a way to determine whether catch caught triggers occur before you trigger them? The JScript code is as follows:

try{  // Do something that causes an error}catch(e){    if ()    {        throw(e);    }        else    {   // do something        }}

A: Sorry, there is no way to check whether the caller will catch your exceptions. However, your issue exposes a potential design defect in your application. When an exception is thrown, all the points say "an accident has occurred, but I don't know how to handle it ". If you can leave without another exception, you can handle this unexpected event. If you can process it and continue, you do not need to raise an exception again. If you cannot process it, follow your caller to process it. You should not decide based on what the caller can handle, but on what you can handle.

If no caller can handle this exception, the correct method is to stop the program. Unexpected programs that cannot be handled will be greatly damaged and must be stopped before they are destroyed. If your caller cannot handle the exception, either rewrite the caller or avoid the exception.

In addition, do not always use exceptions as the main control flow. Exception Handling is specially designed and implemented to manage fatal errors, so this is all aspects that should be used.

Q: In ASP. NET (especially with Visual Basic), how do you pass form data to a webpage? When an ASP. NET webpage is displayed, the form operation field is automatically changed to pass to itself. I need to display the logon page. When a user clicks "login", the form data can be transmitted to other websites (the website created uses request. Form to capture my data ). I know that I can capture data myself and pass it into the query string, but this is not optional. I must pass it to another website.

A: If you only use htmlcontrol on the form, all you need to do to pass it to another page is to delete runat = "server" from the form tag ", set the operation attribute to the URL you want to pass. If you do not add runat = "server", the form element is sent to the unchanged client. This does not prevent you from setting the htmlcontrol value on the form in the page_load event of the web form.

If you use webcontrol, runat = "server" is required on the form ". However, you can still pass it to another page. For details about this situation, see passing server control values between pages.

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.