Posting this here in case this information is helpful to other developers:
As of visionOS 26.3 beta 1, onWorldRecenter has two significant issues: (FB21557639)
-
Memory Leak: When
onWorldRecenteris assigned to aRealityViewwithin anImmersiveSpace, it appears to retain a strong reference to the view's internal SwiftUI context. When the immersive space is dismissed, the view's@Stateobjects will not be deallocated. Also, each time the immersive space view's body is executed, additional state storage will be allocated and leaked. -
Multiple Callbacks: When the user long-presses the Digital Crown, the
onWorldRecenterclosure will be called multiple times, once for each past view body execution, including those of immersive space views that have been previously dismissed.
Although these issues seem to be most prevalent when onWorldRecenter is used with an ImmersiveSpace, they may also occur in the context of a WindowGroup under certain circumstances.
It's possible to work around this problem by moving onWorldRecenter to an empty overlay view within the app's primary WindowGroup and forwarding the world recenter events to ImmersiveSpace views through a notification system, coupled with a debouncer as an extra precaution.