Fixed memory leak with StatefulArray creation, etc.

Also make sure statefularray.instanceof(StatefulArray) works.