Mekire wrote:As soon as a variable goes out of scope in a function, or there are no remaining references to an object, the memory is reclaimed.
Actually, Python won't necessarily garbage collect it right away. It will definitely do so if it needs memory but you don't actually know when that will happen.
raafat wrote:What about vari1,vari2 ? should i delete them or will Python do so ?
As Mekire said, Python will do it for you, but just as added incentive for you to not do it yourself, if you use the del
keyword it's much like the variable going out of scope, it can be garbage collected but you don't know that it will be.
Do note though that even if you did
need to delete a variable before it goes out of scope, realize that doing so on large data structures is the only time it makes sense. You wouldn't do it to an int or anything.
Join the #python-forum IRC channel on irc.freenode.net for off-topic chat!
Please prefer not to PM members. The point of the forum is so that anyone can benefit. We don't want to help you over PMs/emails/Skype chats that others can't benefit from