Check SafeHandleBase for reference. Sorry for not linking, but I'm on mobile atm.