further clean up to releaseBuffer function.