original:
function draw_once(sv)
draw_vehicle(sv);
draw_sonic_line(sv);
end
new:
draw_vehicle(sv);
draw_sonic_line(sv);
clear sv; %%%%%%%%%%%%%%%%%%%%%%% after this added, memory will not increase in the for loop.
end
This test demonstrates that if you do not clear that memory, even after this function is finished, it will not automatically destroy sv to release this memory but keep it.
Very important and puzzling lesson!