"Unable to execute the freed script code" error causes and solutions _javascript tips

Source: Internet
Author: User
Many Web developers may have encountered this problem, the program inexplicably appears "unable to execute code that has been freed script," error row 1, column 1. For this message description is not, the ranks of the description is confusing JS error, I believe that all debugging JS program friends are the most depressed also the most hated things! Encounter this problem, the simplest way to directly put the wrong to Baidu or Google that small input box to let them first to point guidance, and then to solve, but this time it is not so easy, in Baidu search seems a lot of people have encountered this problem, but are what QQ space error, Crazy Halo, Or just ask no answer, stuffy!

Where does this mistake start? There is no way, but also guess is try...catch jump error, looking for a long time finally found the wrong location, but found that there is no problem to write, and then racked their brains to think about the process of interpretation, there is still no clue. Continue to Baidu, suddenly in a Web page to see a sentence: When a page closes will automatically release the page JS. A short speech gave me no small inspiration. Check to see if my program has a page turned off or turned on, and found that it was performing a turn, and then came back to this page with an error. All of a sudden I think I understand.

Scene: The page has A and B two frames page iframe, in the B page through JS to a function reference (function pointer) to a page and save in a page of a variable, a page can use this reference to operate B page or the implementation of the B page of some programs, Remember: The variable at this time on page A is holding the pointer (memory address) of a function on page B. When the B page is refreshed or redirected, the function pointer in page b changes as the B page is rebuilt, but a still retains the pointer (memory address) passed before the B page refreshes. At this point, the variable in page A will not be able to access the corresponding function on page B through the pointer address (because the function pointer address has changed and the original memory pointer has been released), so that an error "cannot execute the freed script code" appears when executed.

Workaround: Add fault-tolerant processing to page A, emptying the saved reference (function pointer) or pointing to a default function when the reference appears to be wrong. In addition, when the B page is loaded again to transfer function references to page A, this error will not occur.

Perhaps the description here is too abstract, look at a demo and then look at the code is easy to understand, first Test, then return URL, then test will appear this 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.