Fix the bug of memory release in documents.