Added reference counting to classes most likely to leak.