Fix refcounting, use Interlocked functions.

4 files changed