Skip to main content

drain

Function drain 

Source
pub fn drain()
Expand description

Let AppKit and SwiftUI finish work they have deferred to the run loop.

Closing a window and releasing a hosting view does not free them: both are torn down on the next turn of the run loop, and a capture loop that never turns it accumulates every frame it has taken — about fifty kilobytes each, which is a hundred megabytes over a couple of thousand frames.

An application has a run loop and never needs this. render calls it for the view it owns. Anything driving render_hosting over a hosting view of its own should call it too, at whatever interval suits: once every dozen frames is enough to keep memory flat, and costs less overall than not doing it at all.