Fixed a memory leak with the rendering code