-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Funcanimation memory leak? #8528
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Python 3, matplotlib 2.0.0 |
https://github.com/matplotlib/matplotlib/blob/master/lib/matplotlib/animation.py#L1608 is probably the line to blame, we keep a cache of recent frame data. We cull that list, but maybe they are never getting gc'd Try adding a few import gc
gc.collect() into the infinite loop (maybe not every loop, but ever 100 or so). |
Related to #8278 |
Hi, some feedback: On MacOS 10.12, Python 3.6 matplotlib 2.0, for an "animation" which is permanently "fed" with measured data, through a generator, the following call ani = animation.FuncAnimation(self.__m_figure, self.animator, self.retriever leads to a maximum memory usage of about 6 GB, whereas "save_count=0" will quickly run out of memory (no difference to just leaving save_count out ...). Adding the gc.collect() makes no difference. self.retriever retrieves data sets from a queue and feeds them to the animator-function one by one, which in turn updates an array and feeds it to the plot via set_data. |
Another bit of information O.k., I have tried to comment out the line self._save_seq.append(framedata) in animation.py (I have copied the file to the local directory and changed the import statement accordingly). There does not seem to be any effect on the problem, though. The memory rapidly vanishes ... |
Here is a simple test case that will double its memory usage (on MacOS 10.12, Python 3.6, Matplotlib 2.0) in about 10-15 minutes: https://gist.github.com/rberlich/67b915ae9a9067373f93c57b3ec78301 |
Apologies for the many messages -- I just think that maybe this may help: I have removed everything with respect to TK from the above example and memory consumption seems to be pretty much stable. So the problem seems to be related to the interaction between tkinter and the animation function (which is quite basic in the example shown in the gist in the last message, I believe). |
Then perhaps it is the Timer?
…On May 2, 2017 9:02 PM, "Beet" ***@***.***> wrote:
Apologies for the many messages -- I just think that maybe this may help:
I have removed everything with respect to TK from the above example and
memory consumption seems to be pretty much stable. So the problem seems to
be related to the interaction between tkinter and the animation function
(which is quite basic in the example shown in the gist in the last message,
I believe).
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#8528 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AARy-HdRBzavzIbJTPEvHUKBmiKuN77Yks5r19I1gaJpZM4NFe5d>
.
|
Hi, not sure I understand where the timer comes in ? In my production code (i.e. not the toy example from the gist) I use a generator, so the animation function is controlled by whether data can be obtained from a queue or not. My "real-world" plots are far more complex than those from the toy example, and produce Gigabytes instead of Megabytes of memory loss. Hence I believe that caching of images by the animation function might indeed be a problem, even though I would not understand why the interaction with tkinter should play a role there. One more thing: A friend of mine has tested the toy example from the gist on Linux, and it doesn't loose memory. Hence this may be a specific MacOS problem. |
Below is another example that quickly looses memory on a Mac (newest Anaconda, Matplotlib 2.02, MacOS 10.12.4). Memory consumption increases from 102 to about 150 MB in roughly 30 minutes on that machine. It is stable and does not increase on a Ubuntu 17.04 system, with the newest Anaconda. I am already explicitly triggering gc and have added the "save_count=None" suggested in other posts.
|
Just to check, this is all with the tk backend? Do you leak memory with the Qt backend on a mac? Thanks for being persistent on this! |
Hi there, no, there is no tk backend involved here. It happens with the code as quoted in my text, which "only" uses Matplotlib. As I am not using any backend here, I believe testing with Qt will not yield any new information. Let me know, though, if I should give it a try. I'd have to find out how, though, as so far I haven't used PyQt yet. One more observation: commenting out the One more funny thing: When adding "blit=True" to the FuncAnimation call, no curve is displayed on the Mac, while it will appear o.k. on the Linux machine. Setting "blit=False" will also show the curve on the Mac. Kind Regards, |
If you are using bliting should work in 2.0 on a mac... |
Also, we ❤️ persistent users. |
- add ```2018-12-30-add-cache_frame_data-kwarg-to-FuncAnimation.rst``` into ```doc/users/next_whats_new```
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
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.
Expected outcome
Matplotlib version
The text was updated successfully, but these errors were encountered: