Iframe dynamically creates and releases memory, and iframe dynamically releases

Source: Internet
Author: User

Iframe dynamically creates and releases memory, and iframe dynamically releases

Recently, I participated in the development of a project. Because the project is a browser-based fat client (RIA) application, iframe is frequently called on the page. Later tests showed that the browser memory remains high, and the larger the memory usage when the iframe page is opened, the more obvious it is in IE browsers. Even if the iframe page is closed, the memory usage is not significantly reduced. ie becomes very stuck when the memory usage reaches about MB. The analysis shows that the iframe is not released, so the memory occupied by all closed iframe cannot be completely released, but the memory usage of iframe will not keep increasing, the memory usage of the entire application is controlled at around MB.


/*** Dynamically create iframe * @ param dom to create the iframe container, that is, create an iframe In the dom. Dom can be div, span, or other labels. * @ Param src the webpage path opened in iframe * @ param onload this event is triggered after iframe is loaded. You can leave it blank * @ return to return the created iframe object */function createIframe (dom, src, onload) {// create iframevar iframe = document in the document. createElement ("iframe"); // sets the iframe Style. style. width = '000000'; iframe. style. height = '000000'; iframe. style. margin = '0'; iframe. style. padding = '0'; iframe. style. overflow = 'hiden '; iframe. style. border = 'none'; // onload event bound to iframe If (onload & Object. prototype. toString. call (onload) = '[object Function]') {if (iframe. attachEvent) {iframe. attachEvent ('onload', onload);} else if (iframe. addEventListener) {iframe. addEventListener ('load', onload);} else {iframe. onload = onload ;}} iframe. src = src; // load iframe to the dom. appendChild (iframe); return iframe;}/*** destroys iframe and releases the memory occupied by iframe. * @ Param iframe the iframe object to be destroyed */function destroyIframe (iframe) {// point iframe to a blank page to release most of the memory. Iframe. src = 'about: Specify ument. clear ();} catch (e) {}// remove iframe from the page iframe. parentNode. removeChild (iframe );}



The dynamically created component in delphi cannot release the memory.

If you use finally to release the code, put all the code containing ADO under try. No matter whether the code below try has an error or exits finally too early, it will always be executed. You can use ADO after this code. If you can use it, it will not be released yet. If you cannot use it, it will be released.
We recommend that you paste the omitted code, or you cannot see the original code.

How to Use the for loop to dynamically generate multiple iframe

<! Doctype html public "-// W3C // dtd html 4.01 Transitional // EN" "www.w3.org/TR/html4/loose.dtd">
<Html>
<Head>
<Title> New Document </title>
<Style>
. Frame
{
Width: 500px;
Height: 200px;
}
</Style>
<Script>
Window. onload = function ()
{
For (var I = 0; I <5; I ++)
{
Var iframe = document. createElement ("iframe ");
Iframe. src = 'www .baidu.com ';
Iframe. className = "frame ";
Iframe. id = "iframe" + I;
Document. body. appendChild (iframe );
}
}
</Script>
</Head>

<Body>

</Body>
</Html>

I just wrote, but there are still problems hi me.

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.