Fix memory leaks on theme changes