Skip to content

Docs: add about -Xdebug to disable "was optimise out" #3553

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Binary file added docs/images/variable-optimised-out.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 9 additions & 7 deletions docs/topics/coroutines-basics.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,16 @@ suspend fun doWorld() {
```
{kotlin-runnable="true" kotlin-min-compiler-version="1.3"}

> You can get the full code [here](../../kotlinx-coroutines-core/jvm/test/guide/example-basic-02.kt).
You can get the full code [here](../../kotlinx-coroutines-core/jvm/test/guide/example-basic-02.kt).

> If you use `suspend` functions, in the debugger, you might see the "was optimised out" text next to a variable's name:
> ![Variable "a" was optimised out](variable-optimised-out.png)
> This text means that the variable's lifetime was decreased, and the variable doesn't exist anymore.
> Debugging code with optimised variables is hard because you don't see their values.
> You can disable this behavior with the `-Xdebug` compiler option.
> __Never use this flag in production__: `-Xdebug` can [cause memory leaks](https://youtrack.jetbrains.com/issue/KT-48678/Coroutine-debugger-disable-was-optimised-out-compiler-feature#focus=Comments-27-6015585.0-0).
>
{type="note"}

<!--- TEST
Hello
World!
-->
{type="tip"}

## Scope builder

Expand Down