473,396 Members | 1,671 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

garbage collector and slowdown (guillaume weymeskirch)

Hello everybody,
To test the python 2.5 garbage collector, I wrote a trivial script
allocating dummy objects of various sizes, then forgetting them in a loop.
The garbage collector seems working well, limiting the memory used.

But I've noticed a near linear slowdown of the execution : after a few
minutes - and several millions of allocated and freed objects, each
iteration take more and more time to execute.

Does anybody have noticed this ? Could python suffers from some memory
fragmentation in long running processes ?

I've got the same slowdown in python 2.5.2 on a 64 bits gentoo linux
box, and on a winxp machine.
FYI, the following script shows this : it prints the seconds taken for
each iteration.

--- cut here ---

import random,sys
from timeit import Timer

class Reference(object):
refcount = {}

def __init__(self):
name = self.__class__.__name__
c = self.refcount.setdefault(name,0)
self.refcount[name] = c + 1
class ClassicSmall(Reference):
def __init__(self):
super(ClassicSmall,self).__init__()
self.a = 0;
self.b = 20000;
self.c = random.randint(0,500)
self.d = random.randint(0,500)
class ClassicBig(Reference):
def __init__(self):
super(ClassicBig,self).__init__()
self.mylist = range(1000)
class Tree(Reference):
def __init__(self,left,right):
super(Tree,self).__init__()
self.left = left
self.right = right
self.data = ''.join([chr(x) for x in range(65,128)])
def doit():
smalls = []
bigs = []
trees = []
for i in xrange(30000):
smalls.append(ClassicSmall())
bigs.append(ClassicBig())
trees.append(Tree(1,2))
if __name__ == '__main__':
t = Timer("doit()", "from __main__ import doit; gc.enable()")
min = 0.9e300; max=0.
try:
while True:
d = t.timeit(1)
if d < min:
min = d
if d max:
max = d
print d
except:
pass
print Reference.refcount
print "max=%f min=%f " % (max,min)

Oct 4 '08 #1
0 851

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: pachanga | last post by:
The Hans-Boehm garbage collector can be successfully used with C and C++, but not yet a standard for C++.. Is there talks about Garbage Collector to become in the C++ standard?
13
by: Mingnan G. | last post by:
Hello everyone. I have written a garbage collector for standard C++ application. It has following main features. 1) Deterministic Finalization Providing deterministic finalization, the system...
28
by: Goalie_Ca | last post by:
I have been reading (or at least googling) about the potential addition of optional garbage collection to C++0x. There are numerous myths and whatnot with very little detailed information. Will...
142
by: jacob navia | last post by:
Abstract -------- Garbage collection is a method of managing memory by using a "collector" library. Periodically, or triggered by an allocation request, the collector looks for unused memory...
8
by: Paul.Lee.1971 | last post by:
Hi everyone, A program that I'm helping to code seems to slow down drastically during initialisation, and looking at the profiling graph, it seems to be the garbage collector thats slowing things...
56
by: Johnny E. Jensen | last post by:
Hellow I'am not sure what to think about the Garbage Collector. I have a Class OutlookObject, It have two private variables. Private Microsoft.Office.Interop.Outlook.Application _Application =...
4
by: Carl Banks | last post by:
On Apr 12, 7:02 am, andreas.eis...@gmail.com wrote: Well, the garbage collector activates whenever allocations exceed deallocations by a certain amount, which for obvious reasons is the reason...
46
by: Carlo Milanesi | last post by:
Hello, traditionally, in C++, dynamically allocated memory has been managed explicitly by calling "delete" in the application code. Now, in addition to the standard library strings, containers,...
1
by: Terry Reedy | last post by:
guillaume weymeskirch wrote: On a related note, there have been past threads reporting that allocating and freeing increasingly long arrays, especially of tuples (as I remember) can take more...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.