Reference counter based cleanup of resources.