Local Lifetimes for Kotlin | Ross Tate @Kotlin
Local Lifetimes for Kotlin | Ross Tate  @Kotlin
Uploaded July 2026 | Updated November 2026, 3 hours ago
Recording brought to you by American Express. americanexpress.io/kotlin-jobs

Many objects are meant to be used only "locally", in the sense that they should not escape from the current function into the "global" world. For example, buildList is given a function that is meant to be used solely by buildList, and buildList calls that function with a MutableList that is meant to be used only by that function. Kotlin's experimental CallsInPlace contract can enforce the former, but currently there is nothing for the latter.

In this talk, I will present a preliminary design we have developed for adding enforceable "locality" to Kotlin as a lightweight form of limited-lifetime objects. With it, library designers can let users write blocks that are guaranteed to have only temporary access to privileged objects. Those objects can be mutable views for building collections, or they can be capabilities indicating that code is executing within the critical section of some lock. Similarly, developers can use locality to prevent accidentally leaking temporary internal objects.

Beyond preventing bugs, locality enables more advanced forms of control. Because local objects cannot outlive the function call that created them, they can safely break to or return from that function, in addition to accessing the current state of its local variables. They can even suspend computation when called within a suspendable function. So locality provides a surprisingly lightweight form of (algebraic) effect polymorphism, with which one can build systems that can work in both synchronous and asynchronous settings.

Besides new functionality, I will cover how this design integrates into the existing Kotlin ecosystem. The design has an "opt-in" nature that lets libraries adopt it as the need arises. At the same time, it is highly backwards compatible, so such adoption can be guaranteed to not break existing users (except where intended to disallow misusages of the library). And while some of the design enables platform-specific optimizations, like stack-allocating objects in Kotlin/Native, overall it can integrate well with existing interopability across platforms. Finally, type-outference enables this new functionality to be checked reliably and efficiently.
Local Lifetimes for Kotlin | Ross TateHow google.com/search builds on Kotlin coroutines for highly scalable, streaming, concurrent serversAdventures in Whimsical UX: The Tug of War Between Delight & Performance | Lauren and EricPeeling back the Layers: A Navigation3 Deep Dive | Marcello Galhardo and Ian LakeEngineering High Performance Multiplatform Graphic Rendering with Jetpack Compose | Rahul and TunjiNested Type Aliases in KotlinTestBalloon: Kotlin testing is easier (and more fun) than you think. Oliver Okrongli, Bernd PrünsterStop making destructuring bugs with Kotlins NEW name based destructuring featureApply for a grant from the Kotlin Foundation with your libraries at kotl.in/grants!A mental model for Kotlin FlowsBuilding Enterprise Ready AI with Koog | Vadim BriliantovStable Instant and Clock Types in Kotlin 2.3
Kotlin by JetBrains |

Local Lifetimes for Kotlin | Ross Tate

SHARE TO X SHARE TO REDDIT SHARE TO FACEBOOK WALLPAPER