Skip to content

Commit 7856270

Browse files
Docs: update tip about -Xdebug to disable "was optimise out" effect
1 parent 8651d7b commit 7856270

File tree

4 files changed

+9
-21
lines changed

4 files changed

+9
-21
lines changed
14.4 KB
Loading

docs/topics/coroutines-basics.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,16 @@ suspend fun doWorld() {
105105
```
106106
{kotlin-runnable="true" kotlin-min-compiler-version="1.3"}
107107

108-
> You can get the full code [here](../../kotlinx-coroutines-core/jvm/test/guide/example-basic-02.kt).
108+
You can get the full code [here](../../kotlinx-coroutines-core/jvm/test/guide/example-basic-02.kt).
109+
110+
> If you use `suspend` functions, in the debugger, you might see the "was optimised out" text next to a variable's name:
111+
> ![Variable "a" was optimised out](variable-optimised-out.png)
112+
> This text means that the variable's lifetime was decreased, and the variable doesn't exist anymore.
113+
> Debugging code with optimised variables is hard because you don't see their values.
114+
> You can disable this behavior with the `-Xdebug` compiler option.
115+
> __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).
109116
>
110-
{type="note"}
111-
112-
<!--- TEST
113-
Hello
114-
World!
115-
-->
117+
{type="tip"}
116118

117119
## Scope builder
118120

docs/topics/debug-coroutines-with-idea.md

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,4 @@ The tutorial assumes you have prior knowledge of the [coroutines](coroutines-gui
9999
* The second coroutine has computed its value and disappeared.
100100
* The third coroutine is calculating the value of `b` – it has the **RUNNING** status.
101101

102-
> You can disable a "was optimised out" feature via the `-Xdebug` compiler option.
103-
> The "was optimised out" feature optimizes variables when you use suspend functions.
104-
> However, debugging a code with optimized variables is hard because you don't see their values.
105-
> Be careful: disabling this feature via `-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).
106-
>
107-
{type="tip"}
108-
109102
Using IntelliJ IDEA debugger, you can dig deeper into each coroutine to debug your code.

docs/topics/debug-flow-with-idea.md

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,6 @@ Create a Kotlin [flow](https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-cor
102102

103103
![Debug the coroutine](flow-debug-2.png)
104104

105-
> You can disable a "was optimised out" feature via the `-Xdebug` compiler option.
106-
> The "was optimised out" feature optimizes variables when you use suspend functions.
107-
> However, debugging a code with optimized variables is hard because you don't see their values.
108-
> Be careful: disabling this feature via `-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).
109-
>
110-
{type="tip"}
111-
112105
## Add a concurrently running coroutine
113106

114107
1. Open the `Main.kt` file in `src/main/kotlin`.

0 commit comments

Comments
 (0)