Hi Team, Please help me find memory leaks issues i...
# decompose
s
Hi Team, Please help me find memory leaks issues in this code :-
Copy code
@OptIn(ExperimentalFoundationApi::class)
@Composable
fun ProjectListingPagerComponent(
    component: ProjectListingComponent,
    state: ProjectListingStore.State,
//    onEvent: (ProjectListingStore.Intent) -> Unit,
//    onOutput: (ProjectListingComponent.Output) -> Unit
) {

    var coroutineScope = rememberCoroutineScope()

    val tabData = remember {
        mutableStateOf<List<StagesRespModel>>(emptyList())
    }

    state?.projectConfig?.counter_list?.let {
        tabData.value = it
    }


    val pagerState = androidx.compose.foundation.pager.rememberPagerState(
        initialPage = 0
    )

    val tabIndex = pagerState.currentPage

    Column(
        horizontalAlignment = Alignment.CenterHorizontally, modifier = Modifier
    ) {
        if (state?.isLoading == true && state?.projectConfig?.counter_list?.isNullOrEmpty() == true) {
            println("Loading...")
            Box(
                contentAlignment = Alignment.Center, modifier = Modifier.fillMaxSize()
            ) {
                CircularProgressIndicator(
                    modifier = Modifier.align(Alignment.Center), color = RbSharedColors.primary
                )
            }
        }
        if (state?.projectConfig?.counter_list?.isNullOrEmpty()?.not() == true) {
            ScrollableTabRow(
                backgroundColor = RbSharedColors.white,
                selectedTabIndex = tabIndex,
                divider = {},
                modifier = Modifier.padding(10.dp).fillMaxWidth(),
                edgePadding = 0.dp,
                indicator = { tabPositions ->
                    tabPositions?.get(tabIndex)?.let {
                        Modifier.tabIndicatorOffset(it).padding(start = sdp(10), end = sdp(10))
                    }?.let {
                        TabRowDefaults.Indicator(
                            it, color = RbSharedColors.ErrorTextColor
                        )
                    }
                },
            ) {
                if (tabData.value.isNullOrEmpty()
                        .not()
                ) tabData?.value?.forEachIndexed { index, _ ->
                    Tab(selected = tabIndex == index, onClick = {
                        coroutineScope.launch {
                            pagerState.animateScrollToPage(index)
                        }
                    }, text = {
                        Row {
                            tabData?.value?.get(index)?.name?.let {
                                Text(
                                    it,
                                    color = if (pagerState.currentPage == index) RbSharedColors.black_020202 else RbSharedColors.gray_667085,
                                    fontSize = Utils.ssp(14),
                                    fontFamily = FontFamily.Default, //Gilroy-Regular
                                    fontWeight = FontWeight.Normal,
                                )
                            }
                            Surface(
                                shape = RoundedCornerShape(sdp(4)),
                                color = if (pagerState.currentPage == index) RbSharedColors.ErrorTextColor else RbSharedColors.gray_c8cdd5,
                                modifier = Modifier.fillMaxWidth()
                                    .padding(start = sdp(5), bottom = sdp(5))
                            ) {
                                Text(
                                    text = tabData?.value?.get(index)?.count.toString() ?: "",
                                    // fontFamily = RbTheme.typography.GILROY_MEDIUM,
                                    color = RbSharedColors.white,
                                    fontFamily = FontFamily.Default,
                                    fontWeight = FontWeight.Medium,
                                    fontSize = Utils.ssp(9),
                                    modifier = Modifier
                                        .padding(
                                            horizontal = sdp(5), vertical = sdp(3)
                                        )
                                )
                            }
                        }
                    })
                }
            }
            HorizontalPager(
                state = pagerState,
                pageCount = tabData?.value?.size ?: 0,
                modifier = Modifier.fillMaxSize()
            ) { page ->
                val stageId = tabData?.value?.getOrNull(page)?.id

                key(stageId) {
                    val currentPage = remember(pagerState.currentPage) { pagerState.currentPage }
                    if (page == currentPage) {
                        Column(
                            modifier = Modifier.fillMaxSize(),
                            verticalArrangement = Arrangement.Center,
                            horizontalAlignment = Alignment.CenterHorizontally
                        ) {
                            ProjectsListingScreen(
                                stageId = stageId,
                                state = state,
                                onEvent = component::onEvent,
                                onOutput = component::onOutput,
                                page = page,
                                pagerState = pagerState,
                            )
                        }
                    }
                }
            }
        } else {
            println("projectConfig not fetched...")
        }
    }
}
ScrollableTabRow & HorizontalPager seems to be leaking