I made simple loop which for each iteration, append
s a number to a list.
After the program has completed, will the memory used by the list be automatically freed?
if __name__ == '__main__': for i in range(100000): list.append(i)
Anyone can explain to me please?
Yes, all memory is freed when the program is terminated. There is just no way in a modern operating system for you to reserve memory and not have it freed when the process is terminated.
Garbage collector is for freeing memory before the program terminates. This way long-running programs won't reserved all the resources of the computer.
If you have a big data structure, and you want the garbage collector to take care of it (free the memory used by it), you should remove all references to it after you're done using it. In this case simple del list
would be sufficient.
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