<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic MapView is Stuck on Screen Rotation in Kotlin Maps SDK Questions</title>
    <link>https://community.esri.com/t5/kotlin-maps-sdk-questions/mapview-is-stuck-on-screen-rotation/m-p/1418914#M417</link>
    <description>&lt;P&gt;&lt;STRONG&gt;Context&lt;/STRONG&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;A href="https://github.com/Esri/arcgis-maps-sdk-kotlin-samples/tree/main/display-composable-mapview" target="_blank" rel="noopener nofollow noreferrer"&gt;Display Composable MapView&lt;/A&gt;&amp;nbsp;is used.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;STRONG&gt;Prerequisites&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;1. Have a slow-slow connection:&amp;nbsp;&lt;SPAN&gt;e.g.: on emulator go to Developers options, Network Download Rate Limit, set 128kb.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;2. Enable screen rotation.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Actions&lt;/STRONG&gt;&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Zoom in to initiate tiles loading;&lt;/LI&gt;&lt;LI&gt;Rotate device when tiles are &lt;EM&gt;partially&lt;/EM&gt; loaded;&lt;/LI&gt;&lt;LI&gt;Repeat several times.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&lt;STRONG&gt;Result&lt;/STRONG&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Map composable is not drawn at all for a period of time (no background, nothing);&lt;/LI&gt;&lt;LI&gt;Heap Dump shows memory leak: several ArcGISMap instances are present (one inside the MapView, and others leak to own StateFlow internally.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;It seems like basemap's baseLayers remote loading is not cancelled when MapView is destroyed due to lifecycle. cancelLoad on any item (ArcGISMap, Basemap, Layer) doesn't give any effect.&lt;/P&gt;</description>
    <pubDate>Fri, 03 May 2024 19:35:43 GMT</pubDate>
    <dc:creator>dev4567</dc:creator>
    <dc:date>2024-05-03T19:35:43Z</dc:date>
    <item>
      <title>MapView is Stuck on Screen Rotation</title>
      <link>https://community.esri.com/t5/kotlin-maps-sdk-questions/mapview-is-stuck-on-screen-rotation/m-p/1418914#M417</link>
      <description>&lt;P&gt;&lt;STRONG&gt;Context&lt;/STRONG&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;A href="https://github.com/Esri/arcgis-maps-sdk-kotlin-samples/tree/main/display-composable-mapview" target="_blank" rel="noopener nofollow noreferrer"&gt;Display Composable MapView&lt;/A&gt;&amp;nbsp;is used.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;STRONG&gt;Prerequisites&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;1. Have a slow-slow connection:&amp;nbsp;&lt;SPAN&gt;e.g.: on emulator go to Developers options, Network Download Rate Limit, set 128kb.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;2. Enable screen rotation.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Actions&lt;/STRONG&gt;&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Zoom in to initiate tiles loading;&lt;/LI&gt;&lt;LI&gt;Rotate device when tiles are &lt;EM&gt;partially&lt;/EM&gt; loaded;&lt;/LI&gt;&lt;LI&gt;Repeat several times.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&lt;STRONG&gt;Result&lt;/STRONG&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Map composable is not drawn at all for a period of time (no background, nothing);&lt;/LI&gt;&lt;LI&gt;Heap Dump shows memory leak: several ArcGISMap instances are present (one inside the MapView, and others leak to own StateFlow internally.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;It seems like basemap's baseLayers remote loading is not cancelled when MapView is destroyed due to lifecycle. cancelLoad on any item (ArcGISMap, Basemap, Layer) doesn't give any effect.&lt;/P&gt;</description>
      <pubDate>Fri, 03 May 2024 19:35:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/kotlin-maps-sdk-questions/mapview-is-stuck-on-screen-rotation/m-p/1418914#M417</guid>
      <dc:creator>dev4567</dc:creator>
      <dc:date>2024-05-03T19:35:43Z</dc:date>
    </item>
    <item>
      <title>Re: MapView is Stuck on Screen Rotation</title>
      <link>https://community.esri.com/t5/kotlin-maps-sdk-questions/mapview-is-stuck-on-screen-rotation/m-p/1418915#M418</link>
      <description>&lt;P&gt;Code snippet I was playing with to try to understand the issue:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="kotlin"&gt;class MainActivity : ComponentActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        // authentication with an API key or named user is
        // required to access basemaps and other location services
        ArcGISEnvironment.apiKey = ApiKey.create(BuildConfig.API_KEY)

        enableEdgeToEdge()

        setContent {
            SampleAppTheme {
                val context = LocalContext.current
                // create a map with a navigation night basemap style
                val map = remember { ArcGISMap(Basemap()) }
                var insets by remember { mutableStateOf(PaddingValues(0.dp)) }

                MapView(
                    modifier = Modifier.fillMaxSize(),
                    arcGISMap = map,
                    isAttributionBarVisible = false,
                    insets = insets
                )
                Column(
                    modifier = Modifier
                        .fillMaxSize()
                        .padding(WindowInsets.systemBars.asPaddingValues()),
                    horizontalAlignment = Alignment.CenterHorizontally,
                    verticalArrangement = Arrangement.spacedBy(16.dp)
                ) {
                    var count by remember {
                        mutableIntStateOf(0)
                    }
                    Button(
                        onClick = { count++ },
                        content = { Text(text = "Click me") }
                    )
                    Text(text = count.toString())
                }

                LaunchedEffect(Unit) {
                    delay(500L)
                    insets = PaddingValues(32.dp)
                }

                LaunchedEffect(Unit) {
                    delay(100L)
                    map.basemap.value?.baseLayers?.add(ArcGISTiledLayer("https://ibasemaps-api.arcgis.com/arcgis/rest/services/World_Imagery/MapServer"))
                    delay(500L)
                    map.basemap.value?.referenceLayers?.add(ArcGISVectorTiledLayer("https://basemapstyles-api.arcgis.com/arcgis/rest/services/styles/v2/layers/arcgis/imagery/labels"))
                }

                DisposableEffect(Unit) {
                    onDispose {
                        map.basemap
                        println("!")
                    }
                }
            }
        }
    }
}&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 03 May 2024 19:38:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/kotlin-maps-sdk-questions/mapview-is-stuck-on-screen-rotation/m-p/1418915#M418</guid>
      <dc:creator>dev4567</dc:creator>
      <dc:date>2024-05-03T19:38:24Z</dc:date>
    </item>
    <item>
      <title>Re: MapView is Stuck on Screen Rotation</title>
      <link>https://community.esri.com/t5/kotlin-maps-sdk-questions/mapview-is-stuck-on-screen-rotation/m-p/1418987#M419</link>
      <description>&lt;P&gt;Also, what I've found in the other project is that ArcGISMap seems to be leaking inside NetworkAuthenticationInterceptor:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="dev4567_0-1714801211729.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/103060i5DB2C097CF7C2193/image-size/medium?v=v2&amp;amp;px=400" role="button" title="dev4567_0-1714801211729.png" alt="dev4567_0-1714801211729.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 04 May 2024 05:41:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/kotlin-maps-sdk-questions/mapview-is-stuck-on-screen-rotation/m-p/1418987#M419</guid>
      <dc:creator>dev4567</dc:creator>
      <dc:date>2024-05-04T05:41:39Z</dc:date>
    </item>
    <item>
      <title>Re: MapView is Stuck on Screen Rotation</title>
      <link>https://community.esri.com/t5/kotlin-maps-sdk-questions/mapview-is-stuck-on-screen-rotation/m-p/1418988#M420</link>
      <description>&lt;P&gt;in previous release 200.3 display-map sample has another issue on rotation with bad connection: I could see two MapView in the heap, which makes me think the problem could be connected with 200.4 leak &lt;span class="lia-unicode-emoji" title=":thinking_face:"&gt;🤔&lt;/span&gt;&amp;nbsp; could it be rendering thread / Looper and the lifecycle in the GeoView?&lt;/P&gt;</description>
      <pubDate>Sat, 04 May 2024 06:26:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/kotlin-maps-sdk-questions/mapview-is-stuck-on-screen-rotation/m-p/1418988#M420</guid>
      <dc:creator>dev4567</dc:creator>
      <dc:date>2024-05-04T06:26:48Z</dc:date>
    </item>
    <item>
      <title>Re: MapView is Stuck on Screen Rotation</title>
      <link>https://community.esri.com/t5/kotlin-maps-sdk-questions/mapview-is-stuck-on-screen-rotation/m-p/1419030#M421</link>
      <description>&lt;P&gt;Also, it feels like reading tiles is done via DefaultDispatcher. As a result -&amp;gt; with bad connection default dispatcher is over-queued easily as it's not intended for long-running operations. If so, http tile reading operations should be switched to IO and asap.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="dev4567_1-1714834965800.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/103073i045610675C829292/image-size/medium?v=v2&amp;amp;px=400" role="button" title="dev4567_1-1714834965800.png" alt="dev4567_1-1714834965800.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="dev4567_0-1714834911882.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/103072i977A61A126329C21/image-size/medium?v=v2&amp;amp;px=400" role="button" title="dev4567_0-1714834911882.png" alt="dev4567_0-1714834911882.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="dev4567_2-1714835625103.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/103074i5CC7B82935FA0CB3/image-size/medium?v=v2&amp;amp;px=400" role="button" title="dev4567_2-1714835625103.png" alt="dev4567_2-1714835625103.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 04 May 2024 16:11:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/kotlin-maps-sdk-questions/mapview-is-stuck-on-screen-rotation/m-p/1419030#M421</guid>
      <dc:creator>dev4567</dc:creator>
      <dc:date>2024-05-04T16:11:42Z</dc:date>
    </item>
    <item>
      <title>Re: MapView is Stuck on Screen Rotation</title>
      <link>https://community.esri.com/t5/kotlin-maps-sdk-questions/mapview-is-stuck-on-screen-rotation/m-p/1419057#M422</link>
      <description>&lt;P&gt;The hacky solution is:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="kotlin"&gt;private fun ArcGISEnvironment.fixCoroutineScope() = this::class.apply {
    val setCoroutineScopeFun = this.java.methods.find { it.name.startsWith("setScope") } ?: return@apply
    val arcgisCoroutineScope =
        CoroutineScope(
            SupervisorJob() + Dispatchers.IO +
                    CoroutineExceptionHandler { _, throwable -&amp;gt;
                        Log.w("ArcGISEnvironment", throwable)
                    },
        )
    setCoroutineScopeFun.invoke(this.objectInstance, arcgisCoroutineScope)
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Would be cool to see setScope fun being open -&amp;gt; to control the dispatcher, but also e.g. if we want to react on exceptions on our (client) terms.&lt;/P&gt;</description>
      <pubDate>Sat, 04 May 2024 21:24:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/kotlin-maps-sdk-questions/mapview-is-stuck-on-screen-rotation/m-p/1419057#M422</guid>
      <dc:creator>dev4567</dc:creator>
      <dc:date>2024-05-04T21:24:15Z</dc:date>
    </item>
    <item>
      <title>Re: MapView is Stuck on Screen Rotation</title>
      <link>https://community.esri.com/t5/kotlin-maps-sdk-questions/mapview-is-stuck-on-screen-rotation/m-p/1502942#M438</link>
      <description>&lt;P&gt;Hello,&lt;BR /&gt;&lt;BR /&gt;Thanks for reporting this and the detailed information you've provided. We have investigated your issues.&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;Map composable is not drawn at all for a period of time (no background, nothing);&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Based on our observations this is expected due to the limited bandwidth of the network set on the device.&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;Heap Dump shows memory leak: several ArcGISMap instances are present (one inside the MapView, and others leak to own StateFlow internally.&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;We have implemented a stress test that rotates the device periodically over a long period of time. Based on this test, we believe that the additional allocations of the ArcGISMap that you are seeing in the heap dump are due to your code that uses `remember` to create an ArcGISMap:&lt;/P&gt;&lt;LI-CODE lang="kotlin"&gt;val map = remember { ArcGISMap(Basemap()) }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;`remember` only caches the object across recompositions, but not if the composition is destroyed and recreated, as it is during a configuration change. This is the reason why you see multiple ArcGISMap instances, as they are allocated with each screen rotation. To ensure only one allocation is used, we recommend using a ViewModel to store the map.&lt;/P&gt;&lt;P&gt;Regardless of whether you use `remember` to store the map or a ViewModel, we have not observed any memory leaks in the memory profiler when running our stress test.&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;Also, it feels like reading tiles is done via DefaultDispatcher. As a result -&amp;gt; with bad connection default dispatcher is over-queued easily as it's not intended for long-running operations. If so, http tile reading operations should be switched to IO and asap.&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;It is correct that network requests are initiated and processed on the DefaultDispatcher, however the requests are actually executed on a separate threadpool owned by the OkHttpClient. While requests are executing, the coroutines on the DefaultDispatcher are suspended but they are not blocking any threads. In other words, the behavior you are observing is working as expected.&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;Would be cool to see setScope fun being open -&amp;gt; to control the dispatcher, but also e.g. if we want to react on exceptions on our (client) terms.&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;That's a good point. We are going to consider this as an enhancement in a future release. In particular, setting a CoroutineExceptionHandler might be useful.&lt;/P&gt;</description>
      <pubDate>Tue, 09 Jul 2024 12:46:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/kotlin-maps-sdk-questions/mapview-is-stuck-on-screen-rotation/m-p/1502942#M438</guid>
      <dc:creator>HudsonMiears</dc:creator>
      <dc:date>2024-07-09T12:46:02Z</dc:date>
    </item>
    <item>
      <title>Re: MapView is Stuck on Screen Rotation</title>
      <link>https://community.esri.com/t5/kotlin-maps-sdk-questions/mapview-is-stuck-on-screen-rotation/m-p/1544635#M498</link>
      <description>&lt;P&gt;Thank you for giving a shot and trying to dig into the issues described! We appreciate it &lt;span class="lia-unicode-emoji" title=":handshake:"&gt;🤝&lt;/span&gt;&lt;/P&gt;&lt;P&gt;1. Regardless where to store the&amp;nbsp; ArcGISMap (btw it's almost impossible to do so in the VM because of sdk's handler mechanism and "Object already owned") there should be no more than 1 instance after the rotation and GC call. Anyway, I'll try to reproduce once more with the new 200.5 – maybe, there is no issue anymore &lt;span class="lia-unicode-emoji" title=":crossed_fingers:"&gt;🤞&lt;/span&gt;&lt;/P&gt;&lt;P&gt;2. I can't agree about the dispatcher: it doesn't matter much which thread okhttp works on if client's (your) coroutine is not suspended actually. As far as I remember &lt;EM&gt;Default&lt;/EM&gt; dispatcher has limited number of active coroutines. And if calls with okhttp inside takes this limit, all other enqueued coroutines gonna wait in the queue – that's what we clearly observe if the i-net connection is really bad. If we switch sdk&amp;nbsp;&lt;EM&gt;to&lt;/EM&gt; IO dispatcher (via reflection) we see the issue no more. However &lt;EM&gt;IO&lt;/EM&gt; dispatcher is elastic – meaning it could overwhelm the process with a lot of threads, so we end up using:&lt;/P&gt;&lt;LI-CODE lang="kotlin"&gt;    val numProcessors = Runtime.getRuntime().availableProcessors()
    val arcGisDispatcher = Dispatchers.IO.limitedParallelism(
        parallelism = numProcessors.div(2).coerceAtLeast(1),
        name = "ArcGis",
    )&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;so, if I could, I would strongly advice to a). give us, clients, an ability to use custom scope and/or dispatcher b). consider switching from Default dispatcher by default, especially for http calls.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Oct 2024 08:53:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/kotlin-maps-sdk-questions/mapview-is-stuck-on-screen-rotation/m-p/1544635#M498</guid>
      <dc:creator>dev4567</dc:creator>
      <dc:date>2024-10-02T08:53:55Z</dc:date>
    </item>
  </channel>
</rss>

