Home > other >  How python used up a function, real-time release the memory
How python used up a function, real-time release the memory

Time:10-25

Format has two functions, for example, roughly as follows, hand to play, ignore the format
Because funb will produce a lot of memory, how do I call after the release of memory


Def funb (x) :
The count=0
For I in range (1, x + 1) :
Count=count + I


Def funa () :
Print funb (10000000000)



Main:
Funa ()

CodePudding user response:

I understand it, if it is used in a function list, element inside a large increase, after return, local variables should be automatically release the memory

CodePudding user response:

You understand funb produce large amounts of memory, a lot of?
The count? For computer bottom, count like a basket, has been to a basket to add something, a memory, so will not produce a lot of,
I? An I a basket, generated a with a finished generating, reoccupy, also won't produce large amounts of memory,

If: you are here defines a variable x, x is a basket, then the function after the operation, these baskets are recycled, (to be automatic recovery)
Python on the basis of their own language, the recovery of memory has been done,

If you want to understand memory usage, go to learn C language, learn more image points,

CodePudding user response:

refer to the second floor bear fury response:
you understand funb produce large amounts of memory, a lot of?
The count? For computer bottom, count like a basket, has been to a basket to add something, a memory, so will not produce a lot of,
I? An I a basket, generated a with a finished generating, reoccupy, also won't produce large amounts of memory,

If: you are here defines a variable x, x is a basket, then the function after the operation, these baskets are recycled, (to be automatic recovery)
Python on the basis of their own language, the recovery of memory has been done,

If you want to understand memory usage, go to learn C language, learn more image points,

The answer is very detailed, thank you
Before I on python2, memory overrun, change python3 is not the problem, after using python3

CodePudding user response:

reference xuzhijun969 reply: 3/f
Quote: refer to the second floor bear fury response:
you understand funb produce large amounts of memory, a lot of?
The count? For computer bottom, count like a basket, has been to a basket to add something, a memory, so will not produce a lot of,
I? An I a basket, generated a with a finished generating, reoccupy, also won't produce large amounts of memory,

If: you are here defines a variable x, x is a basket, then the function after the operation, these baskets are recycled, (to be automatic recovery)
Python on the basis of their own language, the recovery of memory has been done,

If you want to understand memory usage, go to learn C language, learn more image points,

The answer is very detailed, thank you
Before I on python2, memory overrun, change python3 is not the problem, after using python3

Can see the store python2 and python3 maximum value, it should not produce large amounts of memory problems, calculation result is exceeds the maximum limit variables can store (this is a guess)
That is, a variable (basket) can store the value of the largest, has a limit, won't make you always put, your funb parameter x (x) is a great value, the count calculated is also a great value, this value may be because the variable stores the maximum fixed, the value is too large, you more than this value, so the complains,
Can go to baidu check reason, take an error, it should be the problem,

CodePudding user response:

Of a local variable in a function after the function can be released

CodePudding user response:

You should do 1 time memory footprint has been drop down from the server, this can refer to https://blog.csdn.net/jiangjiang_jian/article/details/79140742

CodePudding user response:

Look at Python garbage collection mechanism, memory recovery not in real time, of course you also can call the gc. The collect () to take the initiative to recycle, look at the others reply not all, some reply is a little knowledge, people don't understand the feeling seems to be correct, so easy to mislead, or want to check the information,
In addition, to generate a lot of data to do again (range (1, x + 1)), the really expensive memory, can use yield to generate an iterator to replace,
  • Related