Ultrashock Forums > Flash > ActionScript
AS3 - Objects and Performance

You are currently viewing our website as a guest which gives you limited access to forums, files and other resources.

Click here to join now for free, and start interacting with our members, download files and much more!

Click here if you are looking for our Flash files and other professional assets.
 
Post Reply | View first unread | Rate Thread Search this Thread | Thread Tools | Display Modes

#1
Bookmark and Share!
AS3 - Objects and Performance
Old 2008-07-22

If you create an object and do not assign it to a variable (see the code below), does it stay in the memory and does it slow down performance? If it does, is there any way to remove it from there?

Code:
new SampleClass();
Any help would be fantastic.
postbit arrow 5 comments | 813 views postbit arrow Reply: with Quote   
M40
Registered User
M40 is offline
seperator
Posts: 62
2005-05-22
Age: 24
M40 lives in Bulgaria
seperator

Ultrashock Member Comments:
Isocase's Avatar Isocase Isocase is offline Isocase lives in United States 2008-07-22 #2 Old  
By not assigning a variable to it you have no way of removing it from memory. It would definitely be wise to assign a variable which will allow you to target the object and remove from memory.
Reply With Quote  
M40 M40 is offline M40 lives in Bulgaria 2008-07-22 #3 Old  
Thanks Isocase,

Here's another thought. Wouldn't garbage collector delete an object that is not assigned to a variable?
Reply With Quote  
Nutrox's Avatar Nutrox Nutrox is offline Super Moderator Nutrox lives in United Kingdom 17 Creative Assets 2008-07-22 #4 Old  
It depends what you are doing inside that class. It will stay in memory if it is being referenced by any other objects or referenced by itself (i.e. by using a static property), or if any of it's methods have been registered as strong event listeners. If an object isn't referenced then it should eventually be cleared from memory.
Reply With Quote  
M40 M40 is offline M40 lives in Bulgaria 2008-07-23 #5 Old  
Last edited by M40 : 2008-07-23 at 13:36.
Thanks Nutrox, very useful post as always!

A few more questions if I may.
1. If an object it not assigned to a variable, can it be referenced by another object?
2. Is there any way I can check if an object that is not assigned to a variable in memory?
3. How long an Event object stay in memory? Here's an example. If you dispatch an event the following way - dispatchEvent(new Event()), how long does that Event object exist in memory?

Thank you!
Reply With Quote  
Nutrox's Avatar Nutrox Nutrox is offline Super Moderator Nutrox lives in United Kingdom 17 Creative Assets 2008-07-23 #6 Old  
1. The short answer is no. If you lose all references to an object then it is lost, there would be no way of referencing that object again. The Array in the following example could never be referenced again:

Code:
new Array();
2. You can use the Profiler in Flex Builder 3 for that, but it can't be done in Flash or directly with AS3 as far as I know.

3. It is difficult to answer that one, not many Adobe peeps can answer it either. Flash runs a garbage collection when it thinks it needs to, normally when memory usage fluctuates quite a bit, but it isn't predictable or consistent.

Reply With Quote  
Thread Tools
Display Modes Rate This Thread
Rate This Thread: