Deployment of public opinion system, memory becomes larger, find the reason.
A small example.
def func ():
Local_list = List (range (10000000))
Func ()
Time.sleep (200)
It can be observed that in the time of sleep 200 seconds, the program's memory has been more than 200 m, although it is a function of local variables, after execution on the outside can not be used, but still occupy large memory.
One more.
Global_list = List (range (10000000))
Del global_list
Time.sleep (200)
It can be observed that in sleep for 200 seconds, the program's memory has been more than 200 m, the reference count becomes 0, but still occupies large memory.
Introducing GC Modules
Insert Gc.collect () before sleep
Look at the memory, memory directly down to 10M, this is what I expected.
The list in this article represents a huge memory variable, which is referred to as a range (10000000). Don't pull any xrange range, I'm just going to use this to simply refer to some huge memory variables.
In the actual process is the download upload huge HTML source, the crawler process if encountered MP4 AVI connection is not filtered, download the MP4 string will be a huge string.
Before there is a place, to the Njinx gateway Interface upload results, found to have been rejected by Njinx, the request is unsuccessful, and the program encountered this situation, has been waiting for 60 seconds to retry, resulting in never can upload, memory never fall down.
Next article, monitoring memory and freeing memory.
Python memory leak, Python garbage manual recycle, 1