```private val _mySharedFlow = MutableSharedFlow<S...
# flow
j
Copy code
private val _mySharedFlow = MutableSharedFlow<SomeEvent>(
  extraBufferCapacity = 10,
  onBufferOverflow = SUSPEND,
)
We often run into debate in code review about choosing the correct value for extraBufferCapacity when MSF is used with tryEmit, the thought being “we could lead to a large amount of memory usage with some high volume of events that havent been collected yet”. The question we have is what is the best way to choose this value or should we consider an alternate approach? It seems arbitrary to us to have to pick a number out of thin air - do you recommend calling tryEmit and using whether it returns false and logging in this case (according to the docs , this only occurs with SUSPEND of onBufferOverflow, correct?) or some other way of choosing - or is this concern misguided?
d
You're not going to be able to get a general answer to this. It depends entirely on what your Flow is doing, and after all, that's the reason for the configuration parameters to exist.
j
thanks for the reply. I wonder if looking at Channel’s default buffer capacity is a way to give us an idea of some sort of sensible default when its “some but we dont know exactly the rate - but likely not a huge quantity”? https://github.com/Kotlin/kotlinx.coroutines/blob/master/kotlinx-coroutines-core/common/src/channels/Channel.kt#L743 . any tips you’ve used in the past for choosing the extraBufferCapacity value?