 creatingImage fun = do
               iptr <- fun
 --              {#call incrImageC#} -- Uncomment this line to get statistics of number of images allocated by ghc
-              fptr <- newForeignPtr releaseImage iptr
+              fptr <- newForeignPtr iptr (freeBareImage iptr) 
               return . S . BareImage $ fptr
 
 creatingBareImage fun = do
               iptr <- fun
 --              {#call incrImageC#} -- Uncomment this line to get statistics of number of images allocated by ghc
-              fptr <- newForeignPtr releaseImage iptr
+              fptr <- newForeignPtr iptr (freeBareImage iptr)
               return . BareImage $ fptr
 
 unImage (S (BareImage fptr)) = fptr


import Foreign.C.Types
import Foreign.C.String
import Foreign.ForeignPtr
import Foreign.Ptr
import Control.Parallel.Strategies
import Control.DeepSeq


{#pointer *IplImage as BareImage foreign newtype#}

freeBareImage ptr = with ptr {#call cvReleaseImage#}

--foreign import ccall "& wrapReleaseImage" releaseImage :: FinalizerPtr BareImage

instance NFData (Image a b) where
    rnf a@(S (BareImage fptr)) = (unsafeForeignPtrToPtr) fptr `seq` a `seq` ()-- This might also need peek?
