From: Ike H. <ha...@nh...> - 2003-04-30 14:18:29
|
Hi all, A few weeks ago I posted asking if anyone else saw the memory leak I saw in Pmw.Blt.Graph(). After doing a bit more playing with sample code, and some method hunting, I found that the memory leak actually exists in Pmw.Blt.Vector and is a known bug in BLT. (apparently patches are comming) But, there is a way aound this. Generally, according to sample code on the Pmw website, Vectors are to be treated *almost* the same as lists (at least that is my impression) so that if you have a line with a vector (or 2 vectors) defining the points on the line, one can just modify the values, or append values on the end or remove them or whatever, the same as on would for a python list. However, doing any of these is the cause of the memory leak. There is an alternative, which is a bit more CPU intensive, but if one is graphing lots of data (as I was when I discovered this) the memory problem goes away. the trick is to list-ify the vector by using the command list(vector) and making modifications to the data in the list object you create, then using Pmw.Blt.Vector.set(list) to 'set' the vector to the data in the list. Example: Old way: vector=Pmw.Blt.Vector() #creation for i in range(10): vector.append(i) #just putting incremental numbers in the vector...doing this alot causes mem probs #updating for i in range(len(vector)): vector[i]=i+1 #this method of updating also causes problems New way: vector=Pmw.Blt.Vector() #creation a=[] for i in range(10): a.append(i) vector.set(a) #updating a=list(vector) for i in range(len(a)): a[i]=a+1 vector.set(a) and voilia, memory leak problem goes away. |