viz: fixed memory leak, issue 3961
Merge pull request #3346 from Nerei:fixed_memory_leak_in_viz