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 at first time, then b = 11 at second time,why is the id(b) at third time same with the first time? does the value 10 is still in the memory? How to free the memory that value 10 takes up?
In python documentation of plain integer objects this is explained. Take a look here. The references for values between -5 and 256 remain the same, so when you change a variable - it actually points to that reference.
If you go beyond that range, you can expect different behavior.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With