Archive for September, 2007
Posted in flash, flex, memory | 1 Comment »
-
Thursday, September 6th, 2007
When you assign a value of a simple type to a variable, the variable actually stores the value (i.e., myNum = 5, myNum actually equals 5). Variables that point to objects are different. Instead of storing the object in the variable, the object exists somewhere else in memory. The variable just stores the address of the object. That address pointing to the object is called a reference.
var mySprite = new Sprite();
This 1) creates a new Sprite object, 2) creates a new variable named mySprite, 3) stores a reference to that new object in the mySprite variable.
Objects take up memory so you should delete them when they’re no longer going to be used.There are two kinds of references, strong and weak. For an object to be deleted in Flash 9 you need to get rid of all the strong references to it. There are five things that hold references to objects:
Best practice tip: You should remove your listener (i.e., stage.removeListener…) regardless of whether or not your reference to the listener function is strong.
When Flash needs more memory, before it asks for more memory from the system it runs garbage collection. Garbage collection uses a mark and sweep method where it runs through all the objects and marks the ones that aren’t being used then later sweeps them away (removes them from memory). The garbage collection says that an object isn’t being used anymore when there are no strong references to it that tie it to the global object. So if the global object has a direct strong reference to the object (i.e., global.mySprite) or a indirect strong reference to it (i.e., global.myObj.mySprite) then that object will stay in memory. If there are no more strong references to the object or there are only weak references to it, then the object will be marked for deletion.Garbage collection is iterative, which means that it doesn’t run through it’s whole process every time. So the object may stay in memory for a while even when it has been marked for deletion. Eventually it will be removed from memory.–Ellis
-
Wednesday, September 5th, 2007
Flash Player 9 has a powerful Virtual Machine that runs ActionScript 3 at speeds worthy of high-end applications while managing memory automatically. To help keep up that performance and minimize unused memory there are some basic principles to remember when building those applications.ActionScript 3 manages memory using a method called “mark and sweep”, which effectively removes data that isn’t referenced by any other part of the application. As long as all references to a piece of data are removed (pointers set to null or assigned to another piece of data) the data can be cleared and the memory freed. However there are often unnoticed references or “memory leaks” that can compound and eventually slow and crash any system. Following are the principles and techniques to keep in mind while building up Flex and Flash applications:
By following these principles and techniques you will be able to avoid most common memory problems. Flex has a built in profiler that will help you identify the remainder of memory and performance issues and help you know where to spend your time in optimization.Code responsibly.– Tyler
Archive for September, 2007
Posted in flash, flex, memory | 1 Comment »
-
Wednesday, September 5th, 2007
Contribute. Share. Learn. Brag about foosball victories. Get some feedback on a design. Decry the quirks of Internet Explorer. Display your last freelance project. Ask a design question. Make an announcement. Demonstrate code skillz.Please register (or email me some content) so I can mark you as an Author/Contributor on the mediaRAIN development blog.(I highly recommend keeping tabs on the posts here – and the comments on them – with RSS)
Archive for September, 2007
Posted in administrivia | Comments Off
Archive for September, 2007
Posted in flash, flex, memory | Comments Off