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

  • Home
  • SEARCH
  • 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 6953807
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:31:33+00:00 2026-05-27T14:31:33+00:00

Is this the correct, most efficient way to recycle objects when creating an array

  • 0

Is this the correct, most efficient way to recycle objects when creating an array of objects?

package com {
    public class CreateList extends MovieClip {
        //this is the object I will be recycling
        private var newProperty:PropertyRow;

        //this is the array I will use to reference the objects
        private var _theRows:Array = new Array();

        public function CreateList() {
            for (var i:uint = 0; i < 1000; i++ ) {
                //null the object
                newProperty = null;

                //create a new instance of the object
                newProperty = new PropertyRow();

                //store a reference to the object before nulling it in the next for loop cycle.
                _theRows.push(newProperty);
            }

            //null the last object that was created in the for loop
            newProperty = null;
        }
    }
}
  • 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-27T14:31:34+00:00Added an answer on May 27, 2026 at 2:31 pm

    Using the new keyword will instantiate a new instance of PropertyRow. The GC won’t free up memory after setting the variable to null, because the instances are still retained in the array. Therefore, using a member variable will not bring any performance advantage over using a temp variable within your creation loop.

    If you’re going to optimize your code for performance, you should first try to always use Vectors instead of Arrays.

    IMPORTANT EDIT

    As I’ve found out while testing vector performance for another question, this is true only for number types! If you are going to use a vector of any object type, Array will in fact be faster! The rest of my answer below still applies, though – just use Arrays instead of Vector.<PropertyRow>.

    END EDIT

    Then, if it’s avoidable, don’t use push(), but bracket syntax (only if you know the exact size of the vector – this is important, otherwise the bracket syntax won’t work):

    var vec_size:int = 1000;
    var myArray:Array = new Array (vec_size); 
    for (var i : int = 0; i< vec_size; i++) {
        myArray[i] = new PropertyRow(); // if you're not setting any properties, you won't even need a temp variable ;)
    }
    

    If you are worried about garbage collection and reusing objects, also check out Adobe’s reference on object pooling.

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

Sidebar

Related Questions

Is this the correct way to obtain the most negative double in Java? double
Is this the correct way to do it? <a id=load href=# class=btn load onclick=request(this);
I was wondering what was the most efficient way to rotate a JavaScript array.
Is this the correct (or even a valid way) to use emums in Objective-C?
This is a simple question: Is this a correct way to get an integer
We are currently investigating the most efficient way of communicating between 120-140 embedded hardware
Will this query work? Is it most efficient? SELECT * FROM `posts` WHERE MATCH
What is the most efficient way of organizing PHP code for a CRUD application?
All, I am wondering what's the most efficient way to check if a row
What do you think? Is this correct or are there memory leaks? Source: #include

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.