memory leak fix according to https://github.com/avalanche123/Imagine/pull/349