title: Memory leak in reading files from Google Cloud Storage at Google App Engine (python)
body: <p>Below is part of the python code running at Google App Engine.
  It fetches a file from Google Cloud Storage by using cloudstorage client.</p>
  
  <p>The problem is that each time the code reads a big file(about 10M), the memory used in the instance will increase linearly. Soon, the process is terminated due to "Exceeded soft private memory limit of 128 MB with 134 MB after servicing 40 requests total".</p>
  
  <pre><code>class ReadGSFile(webapp2.RequestHandler):
      def get(self):
          import cloudstorage as gcs
  
          self.response.headers['Content-Type'] = "file type"
          read_path = "path/to/file"
  
          with gcs.open(read_path, 'r') as fp:
              buf = fp.read(1000000)
              while buf:
                  self.response.out.write(buf)
                  buf = fp.read(1000000)
              fp.close()
  </code></pre>
  
  <p>If I comment out the following line, then memory usage in instance does change. So it should be the problem of webapp2. </p>
  
  <pre><code>  self.response.out.write(buf)
  </code></pre>
  
  <p>It is supposed that webapp2 will release memory space after finishing the response. But in my code, it does not.  </p>