Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

AS3 Best way to clear an array

Explorer ,
Jul 15, 2014 Jul 15, 2014

What is the best way to clear an array? (performance and resources)

array.length = 0;

array = [];

array.splice(0);


TOPICS
ActionScript
1.4K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jul 15, 2014 Jul 15, 2014

array.length=0;

Translate
Community Expert ,
Jul 15, 2014 Jul 15, 2014

array.length=0;

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 15, 2014 Jul 15, 2014

If i use something like this:

arr = new Array();

some code

.

.

.

arr = new Array()

The variable arr won't be replaced faster in the memory with this new one?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 16, 2014 Jul 16, 2014

that's creating a new array which is extra work, and it's adding an array to the objects that flash will gc, and that's extra work.

assigning the length to 0 is the most efficient way to clear an array.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 16, 2014 Jul 16, 2014

Thanks.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 17, 2014 Jul 17, 2014
LATEST

you're welcome.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines