| Reference | Downloads | Github

Increasing memory usage - memory leak?

URL of experiment: defcon_builder [PsychoPy]

Description of the problem:

There is a build up in memory usage over the course of my experiment until at some point the experiment starts to lag and later on the tab of the browser crashes. I guess that’s what they call a memory leak?

OS: Ubuntu 18.04
**PsychoPy version: 2020.2.2
**Standard Standalone?: no (Anaconda environment)
** Browser: Firefox 79.0

I’m using the Builder with code components written in JS. In each trial of the experiment there are 409 visual elements (visual.Polygon or visual.Rect) presented on the screen (via setAutoDraw). There is one dictionary and two arrays that grow over the course of the experiment (one additional entry (float) per trial).

Since every single element is logged, the log file accumulates to a size of up to 300 MB (with approximately 2 million lines) after around 1000 trials. Might the accumulation of log entries cause a visible increase of RAM usage over time?

I already tried to switch off the log messages (by commenting out lines in core-2020.2.js) but the memory usage still increases over trials. Is there a function to properly switch off the log file or change the logging level in an online experiment?

I also tried to replace some of the visual elements (~273 of the 409 in total) by using images instead but the build up in memory usage still consists (smaller but still there). Additionally this compromise comes with the cost of downloading a lot of stuff at the start of the experiment wich is inconvenient for the participants.

I wrote the memory usage during the experiment to a file (with all the measures described above already implemented). This is what it looks like as a plot:

Do you have any idea where the increase in memory usage might come from?
Do you know any approach to use for debugging in such a case?

I had hoped that this would be fixed in 2020.2

I would use polygons rather than images but make sure that nothing is set to update every frame in the components. Make each frame changes in code components but only when the parameter has actually changed.

I thought the bugfix suggested by frank.papenmeier worked (see the last entry in PsychoJS platform version 2020.1 - Memory Leak in Visual Stimulus Setters).
And the bugfix seems to be included in the visual-2020.2 code (Polygon & Rect inherit the _updateIfNeeded()-function with the bugfix in class ShapeStim) as well.
So I guess that specific issue should be fixed in 2020.2?

In the each frame tabs of my experiment, there are if conditionals to decide whether to continue the routine occasionally. Besides there is no code in the each frame tabs…

Hi there: I am having a similar problem when testing my task on Prolific. It seemed to happen on all browsers, Firefox seems to be the best and Chrome the worst with crashes. Did you solve the issue by any chance?

Dear @kimSpeck, @YT_HAN, apologies for the late response. This is likely a bug on our end. Many thanks for flagging, the details you have provided are extremely helpful. Would it be possible to grant me or our support account developer access to your GitLab repositories so that I can investigate some more? Here to help, thanks, s.

1 Like

Since this issue doesn’t affect most of the tasks implemented online, the priority is understandably not in one of the top ranks.

I invited your account to the GitLab repository. Don’t hestitate to contact me if you need anything!
Thanks for the help! It is greatly appreciated!

1 Like

Dear @sotiri, thanks for replying so quick! I’ve just added you to the repo that I detailed in the other post Severe memory leak issue for all browsers. Unfortunately, in my case, I really need to solve it quickly and collect data soon. So any advice is greatly appreciated. One specific direction that I am considering is if using the bugfix with 2020.1 would work?

Hi @kimSpeck, apologies again for the late response! Maybe I’m doing something wrong, but I was unable to run the study you link to because of a missing .csv file? If anything I would expect using images instead of shapes to also require a lot of resources.

You’re absolutely right of course, accumulating log entries or a large number of array elements on each frame are very likely to cause performance bottlenecks and to consume more and more memory. Those parts of the script might need tweaking.

To that effect, I have created an extra “no-logging” branch and a corresponding merge request to hopefully answer how to turn off logging without having to edit PsychoJS internals. Please let me know if that fails to address the issue.

Many thanks for your patience, here to help, s.