Refactor state and memory management

* Handle state management at the Actionscript level
* Improve memory management on iOS
* Simplify native implementations