Added fix for the memory leak and a test example from a discussion about the issue.