Thank you very much.<br>Steve Holden, I post my soucecode at my blog here:<br><a href="http://hiparrot.wordpress.com/2005/12/08/implementing-a-simple-net-spider/">http://hiparrot.wordpress.com/2005/12/08/implementing-a-simple-net-spider/
</a><br>I wish you can read and give me some suggestion. <br>Any comments will be appreciated.<br><br><div><span class="gmail_quote">On 12/2/05, <b class="gmail_sendername">Steve Holden</b> <<a href="mailto:steve@holdenweb.com">
steve@holdenweb.com</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">could ildg wrote:<br>> In java and C# String is immutable, str=str+"some more" will return a
<br>> new string and leave some gargabe.<br>> so in java and C# if there are some frequent string operation,<br>> StringBuilder/StringBuffer is recommanded.<br>><br>> Will string operation in python also leave some garbage? I implemented a
<br>> net-spider in python which includes many html string procession. After<br>> it running for sometime, the python exe eats up over 300M memory. Is<br>> this because the string garbages?<br>><br>If you create garbage in a Python program it will normally be collected
<br>and returned to free memory by the garbage collector, which should be<br>run when memory is exhausted in preference to allocating more memory.<br>Additional memory should therefore only be claimed when garbage<br>collection fails to return sufficient free space.
<br><br>If cyclic data structures are created (structures in which components<br>refer to each other even though no external references exist) this could<br>cause problems in older versions of Python, but nowadays the garbage
<br>collector also takes pains to collect unreferenced cyclic structures.<br><br>> If String in python is immutable, what class should I use to avoid too<br>> much garbages when processing strings frequently?<br>>
<br>The fact that your process uses 300MB implies that you are retaining<br>references to a large amount of data. Without seeing the code, however,<br>it's difficult to suggest how you might improve the situation. Are you,
<br>for example, holding the HTML for every spidered page?<br><br>As a side note, both C# and Java also use garbage collection, so if your<br>algorithm exhibits the same problem in all three languages this merely<br>confirms that the problem really is your algorithm, and not the language
<br>in which it is implemented.<br><br>regards<br>  Steve<br>--<br>Steve Holden       +44 150 684 7255  +1 800 494 3119<br>Holden Web LLC                     <a href="http://www.holdenweb.com">www.holdenweb.com</a><br>PyCon TX 2006                  
<a href="http://www.python.org/pycon/">www.python.org/pycon/</a><br><br>--<br><a href="http://mail.python.org/mailman/listinfo/python-list">http://mail.python.org/mailman/listinfo/python-list</a><br></blockquote></div><br>