Files
redwood/redwood-protocol-host
Jeff Holliday 5c49a0bcc2 Fix memory leaks in Redwood UIView components (#2899)
* Fix memory leaks in UIView layout components

Use WeakReference to break retain cycles in UIViewBox and UIViewFlexContainer.

In Kotlin/Native, lambdas and anonymous objects create strong references by
default. The SizeListener callbacks were capturing their parent containers
strongly, creating retain cycles that prevented deallocation:

- UIViewBox.View → children → insert lambda → SizeListener → View
- UIViewFlexContainer → NodeSizeListener → enclosing container

This caused UI components to remain in memory after they should have been
deallocated (e.g., after logout), along with their associated graphics
buffers (VM: Memory Tag objects).

The fix uses WeakReference for the captured parent references, allowing
proper cleanup when the parent containers are no longer needed.

* Fix memory leak in RedwoodUIView sizeListener

Use WeakReference to break retain cycle in RedwoodUIView's sizeListener.

The sizeListener was capturing valueRootView strongly, creating a retain cycle:
RedwoodUIView → valueRootView → sizeListener → valueRootView

This prevented RedwoodUIView instances from being deallocated after they were
removed from the view hierarchy.

The fix uses WeakReference for the captured valueRootView reference, allowing
proper cleanup when the view is no longer needed.

* Fix memory leak: Clear widgetSystem in HostProtocolAdapter.close()

The HostProtocolAdapter was retaining a reference to the WidgetSystem even after
close() was called. This created a leak chain:

HostProtocolAdapter (Kotlin) → WidgetSystem (Kotlin) → RealTreehouseWidgetFactory (Swift) → ContentListener (Swift)

This prevented Swift objects from being deallocated even though they had no
strong references visible in the memory graph, because they were being retained
by Kotlin/Native's reference counting.

The fix makes widgetSystem nullable and clears it in close(), breaking the
Kotlin→Swift reference chain and allowing proper cleanup.

* Add CHANGELOG items for the leaks
2026-01-09 00:19:23 +00:00
..
2025-09-11 16:46:48 -04:00