Valgrind/massif suggests libostree is allocating (and probably leaking) significant memory
I've been looking into memory consumption for Pop!_OS's fork of Appcenter (https://github.com/pop-os/shop/issues/257). I haven't done any profiling on Elementary, but I'd be interested to know if the results are similar.
The output from Valgrid's massif tool seems interesting:


I'd need to do more testing and get more familar with massif to understand if this 879.8 MiB is (largely) leaked, but it seems considerable for even peak memory consumption from that library.
This seems to indicate that most of the excessive memory consumption we've been seeing with Pop Shop (and presumably Appcenter) is allocated by libostree, a dependency of libflatpak. It may not be well tested for long running applications.
This Gnome Software issue looks like they may have a similar problem.
Steps to Reproduce
- Build Appcenter.
- Run
valgrind --tool=massif --depth=5 --alloc-fn=g_malloc --alloc-fn=g_realloc --alloc-fn=g_try_malloc --alloc-fn=g_malloc0 --alloc-fn=g_mem_chunk_alloc build/src/io.elementary.appcenter(as suggested in Gnome Optimization Guide). - Run for a while allowing memory consumption to grow. Doing a few things (with painfully slow response due to valgrind). Exit.
- Use
massif-visualizerto display results.
Platform Information
Compiled from 42320e94c534531a16803805999f98603eae38d9 on Pop!_OS 20.10, with libostree 2020.6-1 and libflatpak 1.8.5-1pop1~1612228017~20.10~7ba959a.
Have you used G_SLICE=always-malloc when using valgrind ? also there is a suppression file for GLib at /usr/share/glib-2.0/valgrind/glib.supp