Add a test for memory leaks when creating a lot of queries
Fix the memory leak when creating queries
Add an explanatory comment
Merge pull request #742 from realm/tg-query-memory-leak

Fix a memory leak when querying tables