guillaume ranquet wrote:
this is how I convert the xml into "plottable" arrays:
"""extracts timestamps and 'what' from 'src' for 'name'"""
buffwhat = 
bufftime = 
sortedbyname = 
element in src if
element["name"] == name]
for i in sortedbyname[:-1]:
if i['name'] == name:
x,y = getnamefrom("cpu0",cpustat,"usage")
(yes, it's a hardware monitor :D)
basically, it seems cpustat is still refcounted somewhere.
what is cpustat? ans elementtree? Anyway, it sure looks like x and y should be full of copies of the data, so you don't have any references that would keep cpustat alive.
Also, it looks like x and y are lists -- when you pass those into MPL, they will be copied to numpy arrays, so you can delete them too, jsut in case they are keeping references to cpustat items.
> I wonder if I should append(copy.copy(i[...])) instead?
rather than that, I'd copy to numpy arrays explicitly:
return np.array(buffwhat), np.array(bufftime)
That's what MPL uses internally anyway, and you'll be clear what you want. If you know how many items you'll have to begin with, you can put the data into np.arrays directly (np.arrays do not support appending).
or If I'm mis-interpreting what I see with top.
you could be -- Python does not necessarily give memory back to the system when it's done with it -- but it should be able to re-use it.
> I'm trying to get infos directly from the gc atm.
you could use sys.getrefcount() (note that it creates a reference itself, so it's always at least 2), but that may nothelp, as it may not be the elementree that has multiple references, but rather something inside it....This is very tricky business -- Python frees you from worrying about memory management almost all the time, but it does mean that you give up control.
Christopher Barker, Ph.D.
Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception