Saturday, November 04, 2017

Finding memory leaks in Actionscript programs

It is true that Adobe Flash is dying. In its official blog FLASH & THE FUTURE OF INTERACTIVE CONTENT, Adobe said it will "stop updating and distributing the Flash Player at the end of 2020". But before that happens, we still need to find a way to support our existing AS3 game because millions of players are playing it.

In my experience, AS3 is not a nice programming language. More sadly, it doesn't have very friendly tools to help developing. Flash Builder is buggy when project structure is getting complicated.

And there is no good tool to help find memory leaks in AS3 programs, neither scout nor flash builder. But AS3 is a language that can easy end up with memory leak bugs, due to it's event registration mechanism.

In the end, we have to spend a few weaks to build our own AS3 memory profiling tool.

It has three parts:

  • A apparat based code injection tool named "apparat profiler", which captures all objects that are instantiated.
  • A AS3 library named "profiler.swc" that we can record object when "object instantation" is captured by "apparat profiler". It also is responsible of sending out recorded objects after requested.
  • A MAT based tool we can receive and analysis recorded objects.



There are conditions we need be carefully of:
  • Not all objects are created via AS3 code, so they can't be captured. The walk around is  to run though all recorded objects and see if they have reference to any objects that aren't captured yet.
  • The whole process is slow. But it's ok since finding a memory leak is very hard and more time consuming then without it.

0 评论: