From 6fb57ef552a6dec18cab980f07d23cff3cb1cedc Mon Sep 17 00:00:00 2001
From: Simon Marlow <simonmar@microsoft.com>
Date: Thu, 19 Jul 2007 16:14:19 +0000
Subject: [PATCH] in hClose, free the handle buffer by replacing it with an
 empty one This helps reduce the memory requirements for a closed but
 unfinalised Handle.

---
 GHC/Handle.hs | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/GHC/Handle.hs b/GHC/Handle.hs
index 261c81c5..263b86d1 100644
--- a/GHC/Handle.hs
+++ b/GHC/Handle.hs
@@ -1158,6 +1158,7 @@ hClose_handle_ handle_ = do
 
     -- free the spare buffers
     writeIORef (haBuffers handle_) BufferListNil
+    writeIORef (haBuffer  handle_) noBuffer
   
 #ifndef mingw32_HOST_OS
     -- unlock it
@@ -1170,6 +1171,9 @@ hClose_handle_ handle_ = do
   		     haType      = ClosedHandle
   		   })
 
+{-# NOINLINE noBuffer #-}
+noBuffer = unsafePerformIO $ allocateBuffer 1 ReadBuffer
+
 -----------------------------------------------------------------------------
 -- Detecting and changing the size of a file
 
-- 
GitLab