SwiftData UndoManager leaks?

In any SwiftData project with undo enabled, I noticed that repeatedly undoing and redoing a change will cause memory to continuously climb. The larger the change, the more memory is consumed. This is surprising to me.

I confirmed this on iOS and macOS using Xcode 15.4 and 16 beta.

To reproduce, simply add undo/redo functionality to any project and repeatedly undo/redo a change. Memory consumption will climb continuously and will not get released.

In Paul Hudson's SwiftData tutorials, he has an entire section about the numerous tricks required to get SwiftData relationships to work correctly. Does anyone know if SwiftData also requires tricks to get the UndoManager to work correctly?

SwiftData undo / redo doesn't need any extra configuration.

If you keep repeating undo / redo, does the memory keep rising, which eventually triggers a low-memory warning / crash, or does it go down at some point? The former case will be system bug, and I suggest that you file a feedback report and post your report ID here for folks to track. The latter will likely be because the system doesn't recycle the released memory immediately, which is the right behavior.

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

SwiftData UndoManager leaks?
 
 
Q