Avoid thread and memory leaks

Follows twin PR in drools-grid