What happens to dynamically declared variables when I'm not using them?

Hello, I'm making a game using Flash Pro cc. But I wonder what happens to aTile, which is dynamically declared MovieClip variable through a loop. And each aTile gets the 2 EventListener's.
for(var i:Number=0; i<pVector.length;i++){
    var aTile:ATile=new ATile();
    aTile.x=pVector[i].x;
    aTile.y=pVector[i].y;
    aTile.gotoAndStop(Math.ceil(Math.random()*Color));
    nVector.push(aTile);
    Spr.addChild(aTile);
    aTile.addEventListener(MouseEvent.CLICK,Clicked,false,0,true);
    aTile.addEventListener(Event.COMPLETE, stop,false,0,true);
     // the current function ends here. what happens to aTile now ?? Is it going to be garbage collected? By the way, this piece of code runs whenever a player starts a new level of my game. And I don't make use of the aTile variable in other functions. I use only the nVector variable. And does declaring a dynamic variable in a loop mean a multiple of them are created? For example, if I loop the piece of code above 5 times, does it mean 5 aTile variables are created? Or each time you declare
var aTile:ATile=new ATile(); again, does it replace the 'old' aTile with the 'new' aTile and therefore only 1 aTile exists after the loop????

I feel there is a gap in understanding of using variables by reference vs. by value. You should look it up.
1. new instructs Flash to create a distinct instance that per se has absolutely nothing to do with aTile variable.
2. REFERENCE to this new instance is assigned to variable aTile. aTile var is a temporary pointer to instance.
3. It does not replace old tile - it replaces reference.
4. If reference to the instance is not stored elsewhere - upon exiting of function this instance will be gced.
5. By creating another reference to the instance you prevent it from GC. One of the ways you preserve instance is by adding it to display list when using addChild.
You can look at this this way (it is a lame example but still it illustrates parts of the concept)
Say you have
1. basket;
2. basket is small and can hold only one apple;
3. table;
4. an apple;
5. apple can be placed into the basket or table;
6. dog who love apples.
7. Dog is trained not to take apples from baskets but table but is free to eat apples that are on the ground.
So, once apple is in the basket or on the table - it is safe.
If you move these entities into the realm of AS3, basket and table become declared variables, apple an instance and dog garbage collector.
What this example demonstrates is that apple exists independently of basket or table. You can put apple to the basket OR on the table OR you can put apple into basket and place basket onto the table.
1. Find apple instance (if you know whether apple is in the basket, on the table or in the basket on the table)
2. Prevent dog from eating apple.
3. Allow dog to eat it (destroy it when garbage collector kicks in) by assuring that apple is in neither basket or on the table.

Similar Messages

  • Just bought the iphone,battery dies within a day.anyway to get the apps not to run when i am not using them?

    just bought my iphone, and the battery dies within one day.  Is there anyway to get the apps not to run when i am not using them to save my battery

    Yeah. Double tap the home button and the screen will shift upwards to show all your running apps. Just press and hold one until they start 'wiggling' then press the 'no entry' like sign that appears in the top left corner of the apps. That'll close them and release the memory and resources they're taking up

  • What happens on iCloud (ex. contacts) when multiple family members use the same Apple ID?

    What happens on iCloud when multiple family members use the same Apple ID?  For example if we all choose to use iCloud for contacts, are they all merged together?  We use the same Apple ID so we can use find my iPhone to keep track of the whole family.

    Of course if you are both connected to the same iCloud account you have the same contacts - what did you expect?. The contacts live on the server and are read from there by the devices; so as you've both managed to sync your contacts up to iCloud they are now inextricably mixed. You can only delete your contacts by deleting individual ones, and doing that will delete them from your phone as well.
    You can only unravel this by
    1. In the iCloud contacts page at http://icloud.com, select all the contacts, click on the cogwheel icon at bottom left and choose 'Export vCard'.
    2. Sign out of System Preferences>iCloud
    3. Create a new Apple ID and open a new iCloud account with it for your own use.
    4. Import the vCard back into the iCloud contacts page.
    5. Go to http://icloud.com and sign in with the original ID. This is now his ID. Work through the contacts individually deleting the ones you don't want him to have. When done sign out and advise him to change his password.
    6. Go to the new iCloud account and delete his contacts individually.
    Of course if you have also been syncing calendars and using the same email address there are problems with doing this.

  • How do you leave your iMac when you're not using it?

    Just curious..
    Hey All..
    I have a 24" iMac 2.8 with a 750GB Hard Drive. I tend to leave it on all the time shutting it down over night probably once a week. I have my settings to turn the display off after 5 minutes and turn off the hard disks "when possible". I just wondered if this was healthy or will it shorten the life expectancy of my pride and joy? I must admit that I do like to leave it on all the time. I leave my Time Capsule on all the time too...should I perhaps shut this down also?
    I have the Applecare program which gives me some piece of mind with my iMac.
    I'd be delighted and interested to hear how you all 'leave' your iMacs when you're not using them.
    Kind regards..
    ~RICKY

    I have my system plugged into a UPS and generally leave it sleeping. There's a window where I have it scheduled to wake up and then sleep again, but it I otherwise sleep it.
    I suspect that sleep probably puts the least wear on your machine and is safe if you have a UPS. FWIW, an early 2007 24" iMac draws 3W of power when it's off, and 10W or so when asleep ( the newer models use less than 6W). During the boot process, power consumption will go 200-220W for ~1 minute. Normal usage it consumes about 100W. Idling, the machine will use between 70-100W depending on the screen brightness, and about 45W if the display is off and machine is idle. Playing something like WoW brings the power consumption up over the 200W mark.
    The mechanical parts wear proportional to the number of times they are used (physical switches), and the electronic parts wear mostly based on the the result of cycles of temperature changes / surges of voltage. Pressing the power-button to power-on the Mac probably puts the most wear on the unit as a whole. That said, under normal circumstances you are not likely to put enough wear on anything but the hard disk to have it fail.

  • Should I unplugged my A Extreme daily when I'm not using the mac?

    Should I unplugged my A Extreme and my Mac daily when I'm not using them?

    Only if you want to save electricity. Otherwise it is not necessary. If anyone else is using the WiFi from the Extreme, it won't be available if it's turned off. Maybe that is not an issue.

  • What happens to iweb-built site when I upgrade from Leopard (10.5.8) to Snow Leopard (10.6.3), and subsequently upgrade to 10.6.8 or even 10.7? Will fonts stay the same? Will layout change? Or anything else change? Thanks

    What happens to iweb-build site when I upgrade from Leopard (10.5.8) to Snow Leopard (10.6.3) and subsequently update that to 10.6.8 or even to 10.7? Evidently iweb has been discontinued. I have version 3.0.3 of iweb now but understand that there's been an update for OS 10.6 so same question goes for this update.
    Will fonts change? Will layout change? Will widgets still work? Links? Will Google Analytics PlugIn still work?
    (Since MobileMe is disappearing, I now save iweb site to local folder on my computer, then upload it to GoDaddy using Cyberduck. I run Google Analytics plug in on folder before its uploaded.)
    My computer, MacBook Pro came with iweb, which has been updated to 3.0.3. Since iweb is discontinued, will upgrade of operating system just ignore iweb so that iweb will run the same as before? Or will it wipe it out? Or change how it currently works (questions above).
    Thanks

    As you now know iWeb and iDVD have been discontinued by Apple. This is evidenced by the fact that new Macs are shipping with iLife 11 installed but without iWeb and iDVD.
    On June 30, 2012 MobileMe will be shutdown. HOWEVER, iWeb will still continue to work but without the following:
    Features No Longer Available Once MobileMe is Discontinued:
    ◼ Password protection
    ◼ Blog and photo comments
    ◼ Blog search
    ◼ Hit counter
    ◼ MobileMe Gallery
    All of these features can be replaced with 3rd party options.
    Currently if the site is published directly from iWeb to the 3rd party server the RSS feed and slideshow subscription features will work. However, if the site is first published to a folder on the hard drive and then uploaded to the sever with a 3rd party FTP client those two features will be broken.
    There's another problem and that's with iWeb's popup slideshows.  Once the MMe servers are no longer online the popup slideshow buttons will not display their images.
    Click to view full size
    However, Roddy McKay and I have figured out a way to modify existing sites with those slideshows and iWeb itself so that those images will display as expected once MobileMe servers are gone.  How to is described in this tutorial: iW14 - Modify iWeb So Popup Slideshows Will Work After MobileMe is Discontinued.
    NOTE: the iLife 11 boxed version Is no longer available at the online Apple Store.  To get a copy you'll have to try Amazon.com or eBay.com.
    This may be of interest to you: Life After MobileMe.
    OT

  • What happens in the back ground when you schedule a Sales Order?

    Gurus,
    What happens in the back ground when you schedule a Sales Order?
    Assemble to Order scenario.
    Edited by: 792050 on May 17, 2011 3:24 AM
    Edited by: 792050 on May 17, 2011 3:24 AM

    If I merge libraries and then back the merged libraries up onto an external drive or DVD, do I just back up the libraries themselves, or do I also back up the original files?
    If you're running a Managed Library, then backing up the Library also backs up the original files.
    I ask because my HDD is getting pretty full. I want to reduce the amount of stuff on it, and the iPhoto libraries are the biggest single consumer of space at the moment (Nearly 100GB).
    1. Quit iPhoto
    2. Copy the iPhoto Library from your Pictures Folder to the External Disk.
    3. Hold down the option (or alt) key while launching iPhoto. From the resulting menu select 'Choose Library' and navigate to the new location. From that point on this will be the default location of your library.
    4. Test the library and when you're sure all is well, trash the one on your internal HD to free up space.
    Regards
    TD
    P.s. If you're running a Managed library, then it's the default setting, and iPhoto copies files into the iPhoto Library when Importing
    If you're running a Referenced Library, then you made a change at iPhoto -> Preferences -> Advanced and iPhoto is NOT copying the files into the iPhoto Library when importing.

  • What happen to my email contacts when i downloaded os 10 yosemite

    what happen to my email contacts when i downloaded os 10 yosemite.
    Thanks,
    Dave

    You need to be more specific on what you are missing.

  • I wish to recycle a number of macs.  What happens to the hard drive when sent to Simms?  Do I need to dismount them?

    I wish to recycle a number of macs.  What happens to the hard drive when sent to Simms?  Do I need to dismount them?

    Hard drives don't die then come back to life. Your drive never died. You just thought it did.
    Obviously, if a hard drive isn't on and spinning its life is longer than when it is always on and spinning. If a hard drive in a laptop is idle it goes to sleep. That's normal because it prolongs battery life. Of course it hardly matters if the computer is running on AC power. The drive may still go to sleep but there's no impact on the battery.
    If the computer is in use 24/7 then its useful life will be less than if it's in use only 12/7 or 8/7. This is both logical and obvious. But in the long run all computers or their hard drives fail. There is little you can do to prevent that. They are meant to be used. If your life is dependent on the computer being usable, then buy another one as a spare. Or at the very least buy a backup drive, keep the computer backed up, then you can worry less about drive failure.

  • What happens to connection to oracle when process exit

    Hi,
    What happens to open oracle connections when a process exit without closing them ?

    The process monitor (PMON) performs process recovery when a user process fails. PMON is responsible for cleaning up the database buffer cache and freeing resources that the user process was using. For example, it resets the status of the active transaction table, releases locks, and removes the process ID from the list of active processes.
    PMON periodically checks the status of dispatcher and server processes, and restarts any that have stopped running (but not any that Oracle has terminated intentionally). PMON also registers information about the instance and dispatcher processes with the network listener.
    Like SMON, PMON checks regularly to see whether it is needed and can be called if another process detects the need for it.
    Ref. Process Monitor Process (PMON)
    Oracle® Database Concepts
    10g Release 2 (10.2)
    Part Number B14220-02
    ~ Madrid.

  • I am getting electric current type shocks whilst using my track pad on my macbook pro. This happens when it is both plugged in to charge and also unplugged. I am left with a constant type pain of prickly pins and needles even when I am not using it.

    I have recently bought a Macbook pro and have noticed that I am getting an electric current running up my fingers when using the track pad. This happens when it is charging but most worryingly it happens when it is not plugged in. It leaves me with pins and needles type feeling in my hand and arm even when I am not using it. Also when I sit it on my lap I get the same electrical current in my legs and down to my feet.
    Surely this cannot be what I should expect with an apple product?, has anyone else experienced this?.
    Yesterday I couldn't bare to use it the current was so strong.  I went out for the rest of the day and suffered with pins and prickly needles all day.

    Two possible courses of action suggest themselves:
    (1) Return your computer immediately to point of purchase and/or authorized service provider.
    or
    (2) Consult with your doctor about your neurological symptoms.

  • What do I do to view images on CS5-64 when it will not open them?

    The program will not open images, either directly or from Bridge.  Using Win 7 on a Dell PC.

    Strange, after rebooting, both Ph CS5 and Bridge are working again.  Thanks for getting with me.
    Date: Fri, 9 Aug 2013 23:30:38 -0700
    From: [email protected]
    To: [email protected]
    Subject: What do I do to view images on CS5-64 when it will not open them?
        Re: What do I do to view images on CS5-64 when it will not open them?
        created by Mylenium in Photoshop for Beginners - View the full discussion
    What exactly? What image files? Do you get any error messages/ warnings? Provide more info.
    Mylenium
         Please note that the Adobe Forums do not accept email attachments. If you want to embed a screen image in your message please visit the thread in the forum to embed the image at http://forums.adobe.com/message/5582783#5582783
         Replies to this message go to everyone subscribed to this thread, not directly to the person who posted the message. To post a reply, either reply to this email or visit the message page: http://forums.adobe.com/message/5582783#5582783
         To unsubscribe from this thread, please visit the message page at http://forums.adobe.com/message/5582783#5582783. In the Actions box on the right, click the Stop Email Notifications link.
         Start a new discussion in Photoshop for Beginners by email or at Adobe Community
      For more information about maintaining your forum email notifications please go to http://forums.adobe.com/message/2936746#2936746.

  • All my email has disappeared from iCloud.  I did not delete it, and now it's working again, but only from 28 August 2013.  What happened to my old emails? How do I get them back? thanks

    All my email has disappeared from iCloud.  I did not delete it, and now it's working again, but only from 28 August 2013.  What happened to my old emails? How do I get them back? thanks

    Have you checked whether the emails are visible at http://icloud.com ? If they are, it's a problem between your Mac and the website; sign out in System Preferences>iCloud and sign back in again.
    If they aren't, then it's a server problem and you need to contact Support. If you currently happen to have AppleCare, either because you recently bought Apple hardware or have paid to extend the inititial period, you can contact them here:
    http://www.apple.com/support/icloud/contact/
    You will need the serial number of the covered hardware.
    If you are not covered by AppleCare, then - in common with other free email services - there is no free support and you may be asked to pay a fee; if so you should argue that this is a problem they've caused (it's not the first time, by the way) and you shouldn't be charged.

  • HT201209 I bought my Apple iTunes & Apple AppStore Card's at Best Buy, but when I try to use them I get this error: The Gift Certificate or Prepaid Card code you entered has not Ben properly activated. What did I do wrong or did Best Buy not scan it right

    I bought my Apple iTunes &amp; Apple AppStore Card's at Best Buy, but when I try to use them I get this error: The Gift Certificate or Prepaid Card code you entered has not Ben properly activated. What did I do wrong or did Best Buy not scan it right! Real Geniuses in that store!

    If so, then review the first link to see if you can troubleshoot your issue yourself. If that doesn't work, then contact iTunes Support via the second link below:
    Invalid, inactive or illegible codes:
    http://support.apple.com/kb/TS1292
    Contact iTunes support here:
    http://www.apple.com/support/itunes/contact/
    Cheers,
    GB

  • HT1605 when i'm not using it it turn off and won't turn on so i have to reset my ipod nano 4th gen just to turn it on. what will i do? is there something wrong with my ipod? is it ok to reset the ipod always?

    when i'm not using it it turn off and won't turn on so i have to reset my ipod nano 4th gen just to turn it on. what will i do? is there something wrong with my ipod? is it ok to reset the ipod always?

    when i'm not using it it turn off and won't turn on so i have to reset my ipod nano 4th gen just to turn it on. what will i do? is there something wrong with my ipod? is it ok to reset the ipod always?

Maybe you are looking for