Backport the ResourceLeakDetector from master

- so that we can take advantage of ReferenceCounted.touch(..) operation