Clean up grid on destruction

This is intended as a fix to #618. The grid leaks memory in a few places when it is destroyed.

Plunker demonstration of the problem is in the linked issue.