Fix for memory-leak in typeahead

Fix for issue #3111