Skip to content

Commit 35c6be1

Browse files
Merge pull request #3553 from Kotlin/new-compiler-option-for-disabling-optimizations
Docs: add about -Xdebug to disable "was optimise out"
2 parents bb4dcde + 61d1df5 commit 35c6be1

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed
82.6 KB
Loading

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

+14
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,17 @@ The tutorial assumes you have prior knowledge of the [coroutines](coroutines-gui
100100
* The third coroutine is calculating the value of `b` – it has the **RUNNING** status.
101101

102102
Using IntelliJ IDEA debugger, you can dig deeper into each coroutine to debug your code.
103+
104+
### Optimized-out variables
105+
106+
If you use `suspend` functions, in the debugger, you might see the "was optimized out" text next to a variable's name:
107+
108+
![Variable "a" was optimized out](variable-optimised-out.png)
109+
110+
This text means that the variable's lifetime was decreased, and the variable doesn't exist anymore.
111+
It is difficult to debug code with optimized variables because you don't see their values.
112+
You can disable this behavior with the `-Xdebug` compiler option.
113+
114+
> __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).
115+
>
116+
{type="warning"}

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

+14
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,20 @@ Create a Kotlin [flow](https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-cor
102102

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

105+
### Optimized-out variables
106+
107+
If you use `suspend` functions, in the debugger, you might see the "was optimized out" text next to a variable's name:
108+
109+
![Variable "a" was optimized out](variable-optimised-out.png)
110+
111+
This text means that the variable's lifetime was decreased, and the variable doesn't exist anymore.
112+
It is difficult to debug code with optimized variables because you don't see their values.
113+
You can disable this behavior with the `-Xdebug` compiler option.
114+
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).
116+
>
117+
{type="warning"}
118+
105119
## Add a concurrently running coroutine
106120

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

0 commit comments

Comments
 (0)