On Wednesday 10 December 2008, mabshoff wrote: > On Dec 9, 10:36 am, Martin Albrecht <[EMAIL PROTECTED]> > > wrote: > > Hi there, > > Hi Martin, > > > I'm trying to understand the following memleak without success. Consider > > three functions: > > > > def f(X): > > try: > > return ZZ(X) > > except TypeError: > > X = ZZ(map(ZZ,X),2) > > return X > > > > def g(X): > > try: > > return ZZ(X) > > except TypeError: > > pass > > > > def h(X): > > X = ZZ(map(ZZ,X),2) > > return X > > > > As you can see below, f leaks: > > > > m = get_memory_usage() > > for i in xrange(10^3): > > _ = f([1,0,1]) > > print get_memory_usage() - m > > > > 4.72265625 > > > > while g and h are clean: > > > > m = get_memory_usage() > > for i in xrange(10^3): > > _ = g([1,0,1]) > > print get_memory_usage() - m > > > > 0.0 > > > > m = get_memory_usage() > > for i in xrange(10^3): > > _ = h([1,0,1]) > > > > 0.0 > > > > So it seems each component of the function is clean but their combination > > leaks. Any ideas? > > My guess would be that maybe another coercion is involved when doing > running h. There have been several issues exposed recently where the > new coercion's caching mechanism did not work and subsequently did > start leaking memory. Two examples are #4639 and #4740. The first one > is still open while the second one has a fix that unfortunately causes > one failure in the pickle jar. > > Other than that I have no idea yet what specifically can go wrong > here. I assume you ran valgrind on the example?
I didn't spot anything obvious in the valgrind logs so far. However, another datapoint. This still leaks. def f(X): try: return ZZ([1,0]) except TypeError, msg: return ZZ(2) m = get_memory_usage() for i in xrange(10**4): _ = f([1,0,1]) print get_memory_usage() - m Also, if I replace ZZ by QQ, QQbar, RDF or RR it still leaks: ZZ: 47.453125 RR: 55.6328125 QQ: 55.5625 QQbar: 25.171875 but I assume all these call Integer.__init__ at some point. However, GF(127) does not leak. Cheers, Martin -- name: Martin Albrecht _pgp: http://pgp.mit.edu:11371/pks/lookup?op=get&search=0x8EF0DC99 _www: http://www.informatik.uni-bremen.de/~malb _jab: [EMAIL PROTECTED] --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to sage-devel@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-devel URLs: http://www.sagemath.org -~----------~----~----~----~------~----~------~--~---