Possible memory leak?

Tuvas tuvas21 at gmail.com
Tue Jan 24 16:51:36 EST 2006


I have a function in a program that works something like this.

def load_pic_data(width,heigth,inpdat, filt=TRUE):
        data=''
        total=0
        tnum=0
        size=100
        for y in range(0,heigth):
                row=''
                for x in range(0,width):
                        index=2*(x+y*width)
                        num=ord(inpdat[index+1])*256+ord(inpdat[index])
                        if(vfilter.get() and d_filter and filt):
                                num=round((num-(d_filter[index/2])))
                        if(num<0):
                                num=0
                        if(num>255*64):
                                num=255*64
                        row=row+chr(num/64)
                data=data+row


The purpose of this part of a program is to take a 14 bit numerical
representation and convert it to an 8 bit representation. This will
later be displayed as an image. However, I've noticed the following
about this code. I was noticing when I took a small picture, it went
really fast, but a larger picture took forever to run through. I added
a print statement to the y portion of the code to see where it was
getting hung up. I noticed that it appears to be running slower as time
goes on. I did a time.time() timestamp to verify this, and had it
confirmed. Any ideas as to what I could do to make it run faster? Note
that if this process is repeated, it runs equally slow.What can I do to
make it run faster? I suspect if I somehow dealocate the row statement
after it's done, that it will run faster, and the data variable when
it's done, but I just don't know how to do so.Thanks!




More information about the Python-list mailing list