Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6101125
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:27:52+00:00 2026-05-23T13:27:52+00:00

Curious question: Take this function: function something():Array { var ar:Array = []; var i:MovieClip;

  • 0

Curious question:

Take this function:

function something():Array
{
    var ar:Array = [];

    var i:MovieClip;
    for each(i in list)
        ar[ar.length] = i.x;

    return ar;
}

Will ar be discarded, or does it continue to chill in my memory, adding to the memory being used each time I call this function?

My question applies to each of these cases:

  1. var val:Array = something(); (obviously val is stored in memory, but what about the original array created in the function?)
  2. something();

Would it maybe be safer to always do this instead?:

return ar.slice();
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T13:27:53+00:00Added an answer on May 23, 2026 at 1:27 pm

    Garbage Collection is done automatically by the flash engine. However it is not done instantaneously. In flash, anything that is not referenced will be GC’ed.

    [See http://www.adobe.com/devnet/flashplayer/articles/garbage_collection.html for more details]

    So for your function case of ‘something()’

    for(var i:int = 0; i<100; i++) {
        something();
    }
    

    Your 100 or so arrays generated will ‘chill’ for probably a few ms (varies) before getting cleared up by GC. However…

    var stupidArr:Array = [];
    for(var i:int = 0; i<100; i++) {
        stupidArr.push( something() );
    }
    

    Your 100 or so arrays WILL STAY, as long as the variable ‘stupidArr’ exists. However if this occurs next.

    stupidArr = null;
    

    OR

    stupidArr.pop(); //Looped as desired
    

    As long as the array in your function ‘something()’ is not refrenced (cleared with each pop, or complete null). By a variable accessible to you. The item will be free’d for GC. And hence will leave the memory.

    So “Array.slice()” for your function is actually a bad idea, cause it doubles the memory consumption before GC (affects performance)

    On another note, if lets say your function has useless variables, for eg: Your loop counters. These too are GC’ed if they are not refrenced at the end of the day. For flash, hence variable and garbage collection is ‘pretty easy’. Just know this rule of thumb.

    If by any means possible, you can programically access the variable, it will persist. If you cant, it will be destroyed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is mostly a theoretical question I'm just very curious about. (I'm not trying
Disclaimer, I not do anything in particular with regards this question, just curious. Is
I have a curious question about efficiency. Say I have a field on a
Quick question, I was curious if there is any difference between a database table
Simple question, but one that I've been curious about...is there a functional difference between
Lets say I have a function that needs to return some integer value. but
I am currently learning jQuery, and I am curious about something. For functions that
I have a curious question... I wanted to know how to maintain chat data
One curious question. if i have a table with column with weblinks then what
curious if anyone might have some insight in how I would do the following

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.