Intercept Play button?

Is there a way to intercept when the play button is pressed (in the editor) so my app can clean up system resources it had allocated?

Checkout the EditorApplication class. Particularly the isPlayingOrWillChangePlaymode flag.