Fixed memory management issue