Newbie completely confused
Gabriel Genellina
gagsl-py2 at yahoo.com.ar
Sat Sep 22 01:16:56 EDT 2007
En Fri, 21 Sep 2007 13:34:40 -0300, Jeroen Hegeman
<jeroen.hegeman at gmail.com> escribi�:
> So the first time around the file gets read in in ~0.1 seconds, the
> second time around it needs almost four seconds! As far as I can see
> this is related to 'something in memory being copied around' since if
> I replace the 'alternative 1' by the 'alternative 2', basically
> making sure that my classes are not used, reading time the second
> time around drops back to normal (= roughly what it is the first pass).
> class ModerateClass:
> def __init__(self):
> return
> def __del__(self):
> pass
> return
>
> class HugeClass:
> def __init__(self,line):
> self.clear()
> self.input(line)
> return
> def __del__(self):
> del self.B4v
> return
> def clear(self):
> self.long_classes = {}
> self.B4v={}
> return
Don't use __del__ unless it's absolutely necesary. ModerateClass.__del__
does nothing, but its mere existence does not allow the garbage collector
to work efficiently. If you explicitey call clear() from HugeClass, you
can avoid using __del__ too. And if B4v is not involved in cycles,
clearing it is not even necesary.
(BTW, all those return statements are redundant and useless)
--
Gabriel Genellina
More information about the Python-list
mailing list