psychopy.org | Reference | Downloads | Github

RAM issues in Chrome

URL of experiment:
https://run.pavlovia.org/mauromanassi/orientation_perc/html

Description of the problem:
Hello,
I have created an online experiment where participants are asked to adjust a bar orientation with left/right arrow keys (400 trials in total). I tested it on my mac and everything works ok. Unfortunately, I had 10 people who tried it online and for 5 of them there were problems:

  1. In the middle of the experiment (it is 400 trials, 35 min), the screen went black and the exp crashed.
  2. Bar adjustment changed speed across the experiment, with the rotation very slow towards the end.
    From what I understand (but please correct me if I am wrong), these are issues that are due to memory in Google Chrome.

Do you have any tip to avoid this kind of problems? My images are all 1-2 Kb, but still the problem persists.

In terms of RAM, what is the most efficient way to avoid RAM issues? For example, as a fixation dot I use an image of a small circle, but would a Polygon be more efficient?

Thanks

Mauro

The most important thing is to make sure you don’t adjust the orientation (or whatever) every frame even when it hasn’t changed. You therefore need to make changes in code.

There’s also a recent post proposing a fix for online memory leakage. I think a search for Pixi destroy might find it.

Yes that found it PsychoJS platform version 2020.1 - Memory Leak in Visual Stimulus Setters

Hey wakecarter,

Thanks a lot for your help. I’m trying to debug a similar issue in my experiment, and happened upon this thread. Could you please further explain what you mean by this:

“The most important thing is to make sure you don’t adjust the orientation (or whatever) every frame even when it hasn’t changed.”

Can you please explain exactly what you mean by this? What sort of code should NOT go in the ‘each frame’ section?

Thanks,
Ilana

I’ve been changing Each Frame updates in components to constant (or each routine) and then setting the changes in a code component.

e.g.

if newval != oldval:
     object.setParam(newval)
     oldval = newval

Would a code like this be efficient?

Begin Routine:
BarOrientation = Math.floor(Math.random() * 180 - 90); #random orientation

gaussbar_p_3 = new visual.ImageStim({
win : psychoJS.window,
name : ‘gaussbar_p_3’, units : ‘height’,
image : ‘images/1Bar.jpg’, mask : undefined,
ori : 0, pos : [0, 0], size : [0.2, 0.2],
color : new util.Color([1, 1, 1]), opacity : 1,
flipHoriz : false, flipVert : false,
texRes : 128, interpolate : true, depth : -17.0
}); #create bar

gaussbar_p_3.setOri((- BarOrientation)); #set starting orientation
gaussbar_p_3.setAutoDraw(true) #draw it

Each Frame:
gaussbar_p_3.setOri((- BarOrientation)); #update depending on key press
gaussbar_p_3.setAutoDraw(true) #draw

End Routine:
gaussbar_p_3.setAutoDraw(false) #stop drawing

Also, I have a separate code component in Begin Routine with the Keypress code:

var keys = new Array();
var mytime = setInterval(RotateBar, 25);
window.addEventListener(‘keydown’,doKeyDown,true);
window.addEventListener(‘keyup’,doKeyUp,true);

function doKeyDown(evt){
keys[evt.keyCode] = true;
}

function doKeyUp(evt){
keys[evt.keyCode] = false;
}

function RotateBar() {
if (37 in keys && keys[37]) {
BarOrientation -= 1;
};
if (39 in keys && keys[39]) {
BarOrientation += 1;
};
}

You aren’t saving the old orientation which means you are running gaussbar_p_3.setOri((- BarOrientation)); every frame rather than just the frames where the orientation changed.

You shouldn’t have setAutoDraw every frame. It’s already auto drawing based on begin routine.

Thank for the reply! I modified the code.
Is this the best strategy or it can be optimized even further for memory issues?

Begin Routine:

BarOrientation = Math.floor(Math.random() * 180 - 90);
BarOrientati = BarOrientation;

gaussbar_p_3 = new visual.ImageStim({
win : psychoJS.window,
name : ‘gaussbar_p_3’, units : ‘height’,
image : ‘images/1Bar.jpg’, mask : undefined,
ori : 0, pos : [0, 0], size : [0.2, 0.2],
color : new util.Color([1, 1, 1]), opacity : 1,
flipHoriz : false, flipVert : false,
texRes : 128, interpolate : true, depth : -17.0
});

gaussbar_p_3.setOri((- BarOrientation));
gaussbar_p_3.setAutoDraw(true)

Each Frame:

if (BarOrientati != BarOrientation){
gaussbar_p_3.setOri((- BarOrientati));
BarOrientation = BarOrientati;
}

End Routine:

gaussbar_p_3.setAutoDraw(false)

External code:

var keys = new Array();
var mytime = setInterval(RotateBar, 25);
window.addEventListener(‘keydown’,doKeyDown,true);
window.addEventListener(‘keyup’,doKeyUp,true);

function doKeyDown(evt){
keys[evt.keyCode] = true;
}

function doKeyUp(evt){
keys[evt.keyCode] = false;
}

function RotateBar() {
if (37 in keys && keys[37]) {
BarOrientati -= 1;
};
if (39 in keys && keys[39]) {
BarOrientati += 1;
};
}

That looks like what I would do. Does it seem to be working now. It’s likely the 2020.2 (due to be released next month) will have fewer memory issues.

1 Like

Ah ok, thanks! Just read your crib sheet by the way–really nice work. Very lucky to have you on this forum.

All best,
Ilana

1 Like