Python memory leak, Python garbage manual recycle, 1

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.