Hi all,
I like to here your thoughts about this 3 to my opinion verry important points:
Memory management – do you do anything to keep the memory usage low?
Speed – same as above what things do you do? and also to keep the framerate steady.
I use as3 and where i can i use weak references for my events (So that the garbage collection can destroy them) and when i don’t need a movieclip anymore i destroy it, remove all events all inner movieclips all references to this movieclip. else it stays in the memory and your site gets slowwwwwwwwwwwwwwwwwwww.
Here some more things:
-Use int instead of number (unless you need more precise numbers)
-Try to replace ENTER _FRAME events with timers or intervals (you can control those much better)
-If timelines are behind a other movieclip and you can not see them set them on stop
-Type everything so flash doesn’t have to look what it is
-Cast instances from a array (myArray[i] as Sprite)
-Dont use movieclips everywhere but use them in this order: 1. shape 2. sprite 3. movieclip
-Dont go to hight with your fps (60 is way to high unless you are using a physics engine does things need it
)
Like to hear some tricks of others think this are some things many people forget.
- Has been a member for 5-6 years
- Author was Featured
- Beta Tester
- Exclusive Author
- Sold between 10 000 and 50 000 dollars
- Bought between 10 and 49 items
- Netherlands
- Referred between 50 and 99 users
- Has been a member for 3-4 years
- Author had a Free File of the Month
- Item was Featured
- Author was Featured
- Beta Tester
- Exclusive Author
- Sold between 10 000 and 50 000 dollars
- Bought between 10 and 49 items
- Referred between 10 and 49 users
Thanks for the advice michel. I’m making a movieclip intensive game, and got to a point where frame rate dropped drastically. I found that cacheAsBitmap can help alot in this case.
Here’s a good read with a nice example for it:
- Has been a member for 3-4 years
- Author was Featured
- Exclusive Author
- Sold between 1 000 and 5 000 dollars
- Bought between 10 and 49 items
- Russian Federation
- Referred between 1 and 9 users
Good tips, Michel! Here are my 2c:
Timers take a lot of memory and slow down the performance;
If you want to remove swf file from memory, you must first deactivate it, and then dereference it (from Moock’s blog).
Things to do Before unloading swf file (for Flash CS3 ):
- Tell any loaded .swf child assets to desable themselves.
- Stop any sounds from playing.
- Stop the timeline, if it is currently playing
- Stop any movie clips that are currently playing
- Close any connected network objects, such as instances of Loader, URLLoader, Socket, XMLSocket, LocalConnection, NetConnections, and NetStream.
- Release all references to cameras and microphones.
- Unregister all event listeners in teh .swf (particularly Event.ENTER_FRAME, and mouse and keyboard listeners)
- Stop any currently running intervals (via clearInterval())
- Stop any Timer objects (via the Timer class’s instance method stop())
In Flash CS4 this all can be automatically by calling the Loader class’s new method unloadAndStop().
I don’t use weak reference for listeners, just remove it when I don’t need them anymore. This way if your project is very memory hungry and the garbage collection acually happens you will know you have all necessary Event Listeners in place and not cleaned by garbage collection.
Michel, I think its a great topic you started and I also would love to hear other developers’ opinion on AS3 .
- Has been a member for 5-6 years
- Author was Featured
- Beta Tester
- Exclusive Author
- Sold between 10 000 and 50 000 dollars
- Bought between 10 and 49 items
- Netherlands
- Referred between 50 and 99 users
the thing with weak references is that if i call System.gc() (progress the garbadge collection) it can remove the unused movieclips with events that have weak references.
O and i always call System.gc() twice like this:
System.gc();
System.gc();
I am not for sure if this is needed i read it somewhere sometime that the first time you call it it only does something like a check and the second time it actually runs it.
- Has been a member for 4-5 years
- Won a Competition
- Contributed a Tutorial to a Tuts+ Site
- Contributed a Blog Post
- Grew a moustache for the Envato Movember competition
- Community Moderator
- Beta Tester
- Exclusive Author
- Sold between 1 000 and 5 000 dollars
- Bought between 50 and 99 items
- United Kingdom
- Referred between 10 and 49 users
very similiar to that, remove your listeners, use as little variables as you can, null your objects when you dont need them, only use EF if you really need to etc…
