No garbage collection (memory leak) under MacOS

This is the biggest problem I have at the moment with Panda on MacOS (which otherwise works very well and is fantastically efficient even on old hardware):
The garbage collection never seems to set in, leading to a constant increase in memory consumption.

Even a simple program that does nothing shows this:

from direct.showbase.ShowBase import ShowBase
from panda3d import core

core.loadPrcFileData('', 'sync-video false')
core.loadPrcFileData('', 'show-frame-rate-meter true')

class MyApp(ShowBase):
    def __init__(self):
        ShowBase.__init__(self)

app = MyApp()
app.run()

Screenshot 2024-09-18 at 09.41.23

In under an hour, the real memory usage reached more than 3 GB on a M1 Mac under MacOS 14.6 (see sceenshot).
The unlimited framerate is only so that the problem shows itself faster, but the increasing memory usage is there with ‘sync-video true’, too.

I use Python 3.12.6 (installed via MacPorts) and Panda3D 1.10.14.
I also tried and the same problem appears with:

  • Panda3D 1.10.14 and Python 3.8 (the earliest version that runs on this computer)
  • Panda3D 1.11.0.dev3323 and Python 3.12

It also seems to affect MacOS 10.13 (on Intel-Mac, there, the memory consumption sometimes goes down but in the long run it rises constantly), but it doesn’t affect the same Intel-Mac under MacOS 10.9 (there, a small game of mine hovers at 95 MB for hours).

Is there something I am missing that could be done about?

So, I was a bit puzzled by this, since it’s not reported by PStats or the leaks utility, but after some investigation I discovered that it’s Apple’s new Metal-based OpenGL driver that is leaking. It seems to be using autorelease a lot and that means that OpenGL calls need to be within an Objective-C @autorelease block. This is not documented anywhere and I can’t find anyone else who has run into this, but putting an autorelease block around the whole frame seems to make the leak go away.

I’ve checked in this fix for the next version of Panda. I would appreciate if you could help test it. Development builds will appear at this link soon:
https://buildbot.panda3d.org/downloads/9f493f588d02591906ba011b2802c5bdb23c2091

Hi, it’s looking much better now.
Screenshot 2024-09-19 at 14.25.39

But there was another problem: the installation package that I tried first doesn’t work:

Traceback (most recent call last):
  File "/Library/Developer/Panda3D/samples/ball-in-maze/main.py", line 12, in <module>
    from direct.showbase.ShowBase import ShowBase
  File "/Library/Developer/Panda3D/direct/showbase/ShowBase.py", line 42, in <module>
    from panda3d.core import *
ImportError: dlopen(/Library/Developer/Panda3D/panda3d/core.cpython-38-darwin.so, 0x0002): tried: '/Library/Developer/Panda3D/panda3d/core.cpython-38-darwin.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e' or 'arm64')), '/System/Volumes/Preboot/Cryptexes/OS/Library/Developer/Panda3D/panda3d/core.cpython-38-darwin.so' (no such file), '/Library/Developer/Panda3D/panda3d/core.cpython-38-darwin.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e' or 'arm64'))

“python -m pip install panda3d-1.10.15.dev45-cp38-cp38-macosx_11_0_universal2.whl” did. I had actually encountered the same problem with the current installer package (for 1.10.14).

The installer package is just for Intel, it seems, with arm64 not included.