gtoolkit: Memory leak

In #82 I already reported some memory issues. Some of which are already solved by fixing the Pillar parser, but I still have recent images that grow indefinitely, no matter what I do. Here are some observations that might help reproducing and solving the issue:

  • As reported in #82, the issue is not trivial to reproduce. It seems not to be a standard Pharo/VM bug, as standard images behave just fine, no ever-increasing memory observed.
  • The VM stats in the system profiler report small memory usage consistently (e.g. 200MB, but Pharo process uses 8GB on macOS). So the error seems not to be in-image memory, rather memory allocated outside the image.
  • The memory starts grow (to over a GB) only after about 30min of an open image, even if idle.
  • I tried running valgrind on the VM to see if it reports something useful, unfortunately it requires a debug build of the VM, which I do not have. It threw an error mentioning that there might even be unsupported instructions used, so it might not work at all.
  • running vmmap on a multi-GB image noted many MALLOC_TINY for many small few-MB-blocks, see https://www.dropbox.com/s/ugozb74syjqawtf/pharo-2019-01-13-12-31-25-vmmap.txt?dl=0
  • All this lead my to the suspicion that FFI might be the culprit, and some memory might not be freed as it should from within the image. I played around with Do image cleanup, Smalltalk garbageCollect, and Reset Bloc Universe, but sometimes it is impossible to get rid of all Moz* structures in FFIExternalResourceManager uniqueInstance’s registry.
  • I have a small image showing FFI objects that are never cleaned up. Unfortunately, #pointersTo seems to break the whole process, memory grows, no response, need to kill image. https://www.dropbox.com/s/co1iygz3ehfdm8r/pharo-2019-01-13-12-31-25.zip?dl=0

There seems to be FFI resources (Path/TextRun/Canvas) allocated by Bloc-Moz2D/Sparta that are never garbage collected, but I cannot explain why not. I have all windows closed, only one old playground for inspection, no Bloc rendering, reset Bloc universe. Still, some resources prevail. Image cleanup, garbage collect, and reset Bloc universe cleans up most, but not everything.

I am still not convinced that these external resources are the only thing leaking. The memory grows on the OS while the image is idling, the external resources seem not to change. Maybe I did not get all of them an there are other memory regions addressed from within the image? How would I inspect these? What would be cool would be a tool that gives an overview over the memory used by the OS process, so that we can explore and filter and trace objects from within the image.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 17 (17 by maintainers)

Commits related to this issue

Most upvoted comments

I have my typer loaded as well, but I also have the issue on fresh images with only GT installed. I am on macOS Sierra. I find it very strange that I seem to be the only one observing the issue, at least Andrei has seen it, so I know I am not getting insane. My goal is still to find a way to reliably reproduce it on my machine, then we will be able to assess whether this is an issue of the environment, e.g. OS, XCode, MacPorts, and whatever can play into this, or if it is platform-independent.