8000 Funcanimation memory leak? · Issue #8528 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content
Funcanimation memory leak? #8528
Closed
@bretcj7

Description

@bretcj7

I have seen similar issues on here closed or fixed but I don't understand if my issue is how the code is implemented or actual issue. Animation seems to keep frames in memory and not release them.

Bug report

I'm using pyplot 2.0 with the FuncAnimation for streaming serial data to a figure where it is continously updated.

For the FuncAnimation to work you have a Figure, Func (function to call at each frame), and Frames (Source of data to pass func and each frame of the animation) fairly simple I thought and it does animate the way I would expect.

However the figure continues to chew up memory until it crashes the Raspberry Pi even though I have the blit flag set to optimize the drawing and only render the new data points.

Full analysis and description here:
http://stackoverflow.com/questions/43548826/pyplot-animation-memory-leak-with-funcanimation?noredirect=1#comment74171567_43548826

Code for reproduction

import matplotlib.pyplot as plt
import matplotlib.animation as animation

#Setup plotting, one figure and two subplots
fig, (ax1, ax2) = plt.subplots(2,1)#,sharex=True)
g_line = ax1.plot([],[],'g')
r_line = ax1.plot([],[],'r')

lines = []
#Add each line to o ur tuples of lines to be plotted
lines.extend(g_line)
lines.extend(r_line)

#Data plotting function, this is call from the animation
#Each data element is in the data list being returned below
def plot_data(data):
  x1 = data[0]; y1 = data[1]; 
  x2 = data[2]; y2 = data[3]; 

  lines[0].set_data(x1,y1)              # Audio - green
  lines[1].set_data(x2,y2)              # Audio thresh - red
  return tuple(lines)

def data_gen():
  my_list = []
  my_list2 = []

  #Main infinite loop for processing of serial data
  while True:
    # Grab input RX serial data
    (my_list, my_list2) = readUART(serReader)

    yield my_list, my_list2

ani = animation.FuncAnimation(fig, plot_data, data_gen, interval=1, blit=True)
plt.show()

Actual outcome

Note - I ran a memory profiler on the entire program minus the plotting and just did it on the while TRUE loop and the memory didn't move past 55mb the entire time I let it run.

# If applicable, paste the console output here
#
#

Expected outcome

Matplotlib version

  • Operating System:
  • Matplotlib Version:
  • Python Version:
  • Jupyter Version (if applicable):
  • Other Libraries:

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0