Use shared_ptr for reference counting instead of hand-rolling it. Change-Id: I147dd6df4e302a2400b184aa88775cf635a57506