adding safe memory release