link text
I got the concept of reference count
So when i do a \"del astrd\" ,reference count drops to zero and astrd gets collected by gc ?
This is t
Could you give some background as to what you are doing?
There's rarely any reason for explicitly using del on variables other than to clean up a namespace of things you don't want to expose. I'm not sure why you are calling del file_name or running gc.collect(). (del sys.modules[filename] is fine - that's a different use of del)
For objects when the exact time they get finalised doesn't matter (eg strings like file_name), you may as well let the variable drop out of scope - when your function finishes, it will be collected, and it won't cause any harm till then. Manually calling del for such variables just clutters up your code.
For objects which need to be finalised immediately (eg. an open file, or a held lock), you shouldn't be relying on the garbage collector anyway - it is not guaranteed to immediately collect such objects. It happens to do so in the standard C python implementation, but not in Jython or IronPython, and is so not guaranteed. Instead, you should explicitly clean up such objects by calling close or using the new with construct.
The only other reason might be that you have a very large amount of memory allocated, and want to signal you are done with it before the variable that refers to it goes out of scope naturally.
Your example doesn't seem to fit either of these circumstances however, so I'm not sure why you're manually invoking the garbage collector at all.