fix thread memory bug.