Add tests for memory leaks and weaken for Issue #81