Python free memory

I want to free some memory, for example, I define a variable:

b = 10
id(b)   # it shows 1935260400

Then I changed the value of b:

b = 11
id(b)  # it shows 1935260432

After that, I changed b again:

b = 10
id(b)  # it still shows 1935260400,why is it same with first time?

Here are the questions, b = 10 the first time, then b = 11 the second time, why is id (b) the third time the same the first time? value 10 is still in memory? How to free memory that takes a value of 10?

+4
source share
1 answer

The python documentation for simple integer objects explains this. Take a look here . Links for values ​​between -5 and 256 remain unchanged, so when you change a variable, it actually points to that link.

, .

+7

Source: https://habr.com/ru/post/1689515/


All Articles