4 Replies
      Latest reply on Apr 9, 2020 7:52 AM by Arnfried Griesert
      Arnfried Griesert Level 1 Level 1 (10 points)

        I created two threads in my macOS app, a main thread that dispatches work every 40ms to a worker thread. This worker thread causes a memory leak. After some debugging it seems that the MTLCommandBuffer is the reason for the leak:


        if let commandBuffer = commandQueue.makeCommandBuffer() {
          // some code here


        I uncommented every code from the worker thread and there is no memory leak anymore. But when I add these lines above and create only an empty command buffer and commit it to the queue then the CPU memory will increase over time.

        The app is running on macOS and compiled with Xcode 10.3 (and Xcode 11 beta with the the same effect).


        Instruments cannot find any leaks. Persistent allocation stays constant over a long time. Only Xcode debugger shows this static memory increase. And only if I create a commandBuffer (with commands encoded or also when empty).


        Edit: I created a new project in Xcode with the game template and selected metal. Same effect. The debugger memory section has the same memory increase over time (nearly 0.1MB each second).