What’s faster for cleaning an array in actionscript 3?
myArray = [];
or
myArray.length = 0;
and why is faster? exist a better method than these? …
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I wrote the following test program:
Using .length = 0 reports 10 milliseconds. Using array = [] reports 21 milliseconds. Clearly, doing .length = 0 is much faster. Additionally, doing array = [] may lead to earlier/more frequent garbage collections as it is probably performing a heap allocation. Garbage collection slows down the application at a later time.
.length = 0 wins for multiple reasons.