Timeout callback tries to run during garbage collection
System information
Fedora silverblue 32.
What is your version of GJS?
I'm using the gnome sdk 3.36, but you can reproduce this also on the gnome sdk 3.34.
const System = imports.system; log(System.version); // 16402
Bug information
Steps to reproduce
Using gnome builder, create a new project with gjs. Inside the _init method inside window.js put this code
this.listBox = new Gtk.ListBox({});
this.add(this.listBox);
for (let i = 0; i < 1000; i++) {
setTimeout(() => {
this.remove(this.listBox);
this.listBox = new Gtk.ListBox({});
this.add(this.listBox);
for (let j = 0; j < 100; j++) {
this.listBox.add(new Gtk.Label({label: "Ok"}));
}
this.show_all();
}, i * 500);
}
The code above creates a new Gtk.ListBox with 100 Gtk.Labels every 500ms. It repeats for 1000 times.
Current behaviour
There are 2 problems: while time passes, the program uses more and more ram. In the beginning it uses 16MiB of ram. Then after every second, it uses 1 more MiB. After reaching around 55MiB, the code stops working: every 500ms, instead of creating a new ListBox again, it shows me this error message. (which is when the code inside the loop is run).
(com.github.ranfdev.LibsoupTest:2): Gjs-CRITICAL **: 22:40:32.671: Attempting to run a JS callback during garbage collection. This is most likely caused by destroying a Clutter actor or GTK widget with ::destroy signal connected, or using the destroy(), dispose(), or remove() vfuncs. Because it would crash the application, it has been blocked.
(com.github.ranfdev.LibsoupTest:2): Gjs-CRITICAL **: 22:40:32.671: The offending callback was SourceFunc().
== Stack trace for context 0x55679586e1a0 ==
#0 55679591e310 i resource:///com/github/ranfdev/LibsoupTest/js/main.js:46 (17f3b22c6718 @ 104)
#1 55679591e270 i resource:///org/gnome/gjs/modules/script/package.js:222 (17f3b228d538 @ 45)
#2 55679591e1e0 i /app/bin/com.github.ranfdev.LibsoupTest:9 (17f3b228d178 @ 53)
Expected behaviour
Regular ram usage. Starts at 16MiB, ends around 16MiB. Doesn't stop working at 55MiB.