As many of us know, memory management in any good size project is a topic that particular attention must be paid to. Over the last 12 months I have seen myself carrying out more and more research into memory management, in a recent project for example I was able to bring the memory usage of a website down by almost 30% in a matter of minutes by integrating simple techniques that I adopt in my own project builds.
In the words of Grant Skinner, "With great power comes great responsibility", and as we find ourselves building more complex applications it is important we consider the internal Garbage Collector and help it carry out its chores. The understanding of the Garbage Collector is another topic in itself, this post is merely a few pointers which I use as a rule of thumb in my work flow.
- Add an Event.REMOVED_FROM_STAGE listener to instance which calls in built function to tidy up assets for garbage collector
- Use weak event listeners
- Remove/ set to null any variables passed into the instance/ container
- Set to null any strings contained by components e.g. label.text = null / image.src = null
- Remove all children of the instance
- Delete the instance i.e. delete this
- Grant Skinner - Understanding garbage collection in Flash Player 9
Leave a Reply