disconnect finished signals on soupmessages to avoid reference cycles

This commit is contained in:
martensitingale 2018-06-22 17:44:37 +00:00
parent f25b51cbe6
commit b049952155
1 changed files with 6 additions and 2 deletions

View File

@ -111,19 +111,23 @@ public class Tootle.ImageCache : GLib.Object {
Soup.Message? msg = in_progress.get(ci);
if (msg == null) {
msg = new Soup.Message("GET", uri);
msg.finished.connect(() => {
ulong id = 0;
id = msg.finished.connect(() => {
debug("Caching %s@%d", uri, size);
var data = msg.response_body.data;
var stream = new MemoryInputStream.from_data (data);
var pixbuf = new Gdk.Pixbuf.from_stream_at_scale (stream, size, size, true);
store_pixbuf(ci, pixbuf);
cb(pixbuf);
msg.disconnect(id);
});
in_progress[ci] = msg;
network.queue_custom (msg);
} else {
msg.finished.connect_after(() => {
ulong id = 0;
id = msg.finished.connect(() => {
cb(pixbufs[ci]);
msg.disconnect(id);
});
}
}