Python memory usage

placid Bulkan at gmail.com
Wed Nov 8 01:18:52 EST 2006


William Heymann wrote:
> On Tuesday 07 November 2006 22:42, placid wrote:
> > Hi All,
> >
> > Just wondering when i run the following code;
> >
> > for i in range(1000000):
> >      print i
> >
> > the memory usage of Python spikes and when the range(..) block finishes
> > execution the memory usage does not drop down. Is there a way of
> > freeing this memory that range(..) allocated?
> >
> > I found this document but the fix seems too complicated.
> >
> > http://www.python.org/pycon/2005/papers/79/python-memory.pdf
> >
> > Cheers
>
> Change range to xrange. It will run faster and use up almost no memory by
> comparison. I know the point you are getting at for releasing memory however
> in this case there is no reason to allocate the memory to begin with.

Thanks for that it has fixed some of the memory problems.  Just
wondering if i continuously create different BeautifulSoup objects
within a xrange() block when does the memory get released for this
object, after the xrange() block, the next iteration of the xrange()
block ?

Cheers




More information about the Python-list mailing list