tidy up resource management during indexing