Optional finalisers for ctypes-allocated memory

Gc.finalise isn't sufficient, since we need to attach the finaliser to the value that holds the raw pointer, which isn't exposed in the public interface.