Fix/memory leaks

This pull request fixes a bunch of memory leaks in perm gen. Leaks were caused by own code and third party libraries.