Skip to content

Documentation: fix OutOfMemoryError for the runnable samples #3631

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
merged 1 commit into from
Feb 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions docs/topics/cancellation-and-timeouts.md
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ resource inside the block that needs closing or release outside of the block.

For example, here we imitate a closeable resource with the `Resource` class that simply keeps track of how many times
it was created by incrementing the `acquired` counter and decrementing the counter in its `close` function.
Now let us let us create a lot of coroutines, each of which creates a `Resource` at the end of the `withTimeout` block
Now let us create a lot of coroutines, each of which creates a `Resource` at the end of the `withTimeout` block
and releases the resource outside the block. We add a small delay so that it is more likely that the timeout occurs
right when the `withTimeout` block is already finished, which will cause a resource leak.

Expand All @@ -398,7 +398,7 @@ class Resource {

fun main() {
runBlocking {
repeat(100_000) { // Launch 100K coroutines
repeat(10_000) { // Launch 10K coroutines
launch {
val resource = withTimeout(60) { // Timeout of 60 ms
delay(50) // Delay for 50 ms
Expand Down Expand Up @@ -446,7 +446,7 @@ class Resource {
fun main() {
//sampleStart
runBlocking {
repeat(100_000) { // Launch 100K coroutines
repeat(10_000) { // Launch 10K coroutines
launch {
var resource: Resource? = null // Not acquired yet
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Resource {

fun main() {
runBlocking {
repeat(100_000) { // Launch 100K coroutines
repeat(10_000) { // Launch 10K coroutines
launch {
val resource = withTimeout(60) { // Timeout of 60 ms
delay(50) // Delay for 50 ms
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Resource {

fun main() {
runBlocking {
repeat(100_000) { // Launch 100K coroutines
repeat(10_000) { // Launch 10K coroutines
launch {
var resource: Resource? = null // Not acquired yet
try {
Expand Down