newForeignPtr

newForeignPtr :: FinalizerPtr a -> Ptr a -> IO (ForeignPtr a)
base Foreign.ForeignPtr
Turns a plain memory reference into a foreign pointer, and associates a finalizer with the reference. The finalizer will be executed after the last reference to the foreign object is dropped. There is no guarantee of promptness, however the finalizer will be executed before the program exits.
newForeignPtr :: Ptr a -> IO () -> IO (ForeignPtr a)
base Foreign.Concurrent
Turns a plain memory reference into a foreign object by associating a finalizer - given by the monadic operation - with the reference. The finalizer will be executed after the last reference to the foreign object is dropped. There is no guarantee of promptness, and in fact there is no guarantee that the finalizer will eventually run at all.
newForeignPtr_ :: Ptr a -> IO (ForeignPtr a)
base Foreign.ForeignPtr
Turns a plain memory reference into a foreign pointer that may be associated with finalizers by using addForeignPtrFinalizer.
newForeignPtrEnv :: FinalizerEnvPtr env a -> Ptr env -> Ptr a -> IO (ForeignPtr a)
base Foreign.ForeignPtr
This variant of newForeignPtr adds a finalizer that expects an environment in addition to the finalized pointer. The environment that will be passed to the finalizer is fixed by the second argument to newForeignPtrEnv.