Free memory when a heatmap is close