Fix memory leaks caused by periodic view refreshing tasks
This branch implements @goapunk's suggested solution to #851 (closed). Credit goes to @ernir for finding the bug and the initial solution, and @goapunk for the improved solution - I just did a quick implementation so we can get this fixed as quickly as possible.
Closes #851 (closed)