Fixed memory leak manifesting itself as "can't access dead object" exception