Q:

How to free python program memory buildup over time, File I/O

I have a function that downloads and saves html pages. Over time, the memory is not being released and the program becomes slow. How can I force release this memory (or what is taking up this memory?   
I think the problem may be with reading, writing the file. Although I call close(), could there be another issue?
The following code is inside a for loop (this is done 1000+ times)
openFile = None

try:
    #download the page
    pageText = getPageAsText(url)

    #write file to disk
    fileName = name
    openFile = open(os.path.expanduser('~')+STATIC_DIRECTORY+'/'+name, 'w')
    openFile.write(pageText)

except Exception:
    traceback.print_exc()

finally:
    if openFile is not None:
        openFile.close()

A:

You can  del to dereference not used variables. It gives a hint to garbage collector to collect the memory earlier. Without your entire code, we cannot see where the memory leak occurs. 
I would also rewrite your code with with, so it handles close by itself.
 pageText = getPageAsText(url)
 with open(os.path.expanduser('~')+STATIC_DIRECTORY+'/'+name, 'w') as f:
      f.write(pageText)

