我正在开发一个主要关注的Android应用程序:

问题描述 投票:0回答:0
基于收到的数据,display内容,包括:

使用
    exoplayer
  1. .

    videos。

  2. 图像使用

    glide

  3. 使用
  4. Webview

    • 待在openSearch中显示内容详细信息。

    • 当应用程序启动时,在Android Profiler中观察到的内存使用率约为
    • 200MB

      。但是,在运行应用程序几个小时后,内存使用情况不断增加。探测仪显示没有内存泄漏(0 leaks

    • ),但是记忆图中的“其他”类别随着时间的推移继续增长。 我已经从我的应用程序运行3个小时后从堆垃圾箱中附上了Dominator树。
  5. 如何确定是什么导致Android Profiler中的“其他”类别增加?

  6. 在使用Exoplayer,Glide,WebView和MQTT的应用中管理内存的最佳实践?

本期可能与本机内存分配(例如,位图,文件手柄)而不是Java Heap内存有关?

任何指导或有关如何调试和解决此问题的建议或建议将不胜感激!
 @SuppressLint("SetTextI18n", "SetJavaScriptEnabled")
@OptIn(UnstableApi::class)
fun startLoop() {
    // If this partition has video content initially, set up ExoPlayer and attach PlayerView
    if (hasVideoInitially) {
        val loadControl = DefaultLoadControl.Builder()
            .setBufferDurationsMs(
                2000, 2000, 1000, 2000
            )
            .build()

        val renderersFactory = DefaultRenderersFactory(context)
            .setEnableDecoderFallback(true)

        exoPlayer =
            ExoPlayer.Builder(context, renderersFactory)
                .setLoadControl(loadControl)
                .build()
        playerView = PlayerView(context).apply {
            useController = false
            setShutterBackgroundColor(Color.TRANSPARENT)
            layoutParams = FrameLayout.LayoutParams(
                FrameLayout.LayoutParams.MATCH_PARENT,
                FrameLayout.LayoutParams.MATCH_PARENT
            )
        }
        playerView?.player = exoPlayer
        partitionContainer.addView(playerView)
    }

    // Create an ImageView for images/PDF
    imageView = ImageView(context).apply {
        layoutParams = FrameLayout.LayoutParams(
            FrameLayout.LayoutParams.MATCH_PARENT,
            FrameLayout.LayoutParams.MATCH_PARENT
        )
        scaleType = ImageView.ScaleType.FIT_XY
        visibility = GONE
    }
    partitionContainer.addView(imageView)

    // Create a WebView for HTML content
    webView = WebView(context).apply {
        layoutParams = FrameLayout.LayoutParams(
            FrameLayout.LayoutParams.MATCH_PARENT,
            FrameLayout.LayoutParams.MATCH_PARENT
        )
        visibility = GONE
        settings.javaScriptEnabled = true
        settings.domStorageEnabled = true
        settings.cacheMode = WebSettings.LOAD_NO_CACHE
        settings.mixedContentMode = WebSettings.MIXED_CONTENT_ALWAYS_ALLOW
        WebView.setWebContentsDebuggingEnabled(true)
    }
    partitionContainer.addView(webView)

    // Create a "No Content" TextView but hide it initially
    noContentTextView = TextView(context).apply {
        text = "No content to play."
        textSize = 18f
        setTextColor(Color.CYAN)
        gravity = Gravity.CENTER
        visibility = GONE
    }
    partitionContainer.addView(noContentTextView)

    // Kick off the main loop
    scope.launch {
        while (isActive) {
            try {
                // Take a "snapshot" of the current contents under the lock
                val snapshot = contentLock.withLock { contentList }

                if (snapshot.isEmpty()) {
                    // If we've *never* played content before, it means we're just waiting for content
                    // so do nothing special. If we have played content before, show "No content."
                    if (hasEverPlayedContent) {
                        // Show the "No content" message
                        noContentTextView?.visibility = VISIBLE
                        noContentTextView?.bringToFront()
                    }
                    delay(2000)
                } else if (snapshot.size == 1 && snapshot[0].contentType.lowercase(Locale.ROOT) == "widget") {

                    // Display the widget once
                    displayWidgetIndefinitely(snapshot[0])
                    // Then break out of the while loop or block the loop.
                    break
                } else {
                    // Hide "No content" message if it was visible
                    noContentTextView?.visibility = GONE

                    // Loop over the snapshot
                    for (item in snapshot) {
                        if (!isActive) break  // If our scope got canceled mid-loop
                        if (!hasFiredFirstContentPlayed) {
                            hasFiredFirstContentPlayed = true
                            onFirstContentPlayed?.onFirstContentPlayed()
                        }
                        hasEverPlayedContent = true
                        displayContent(item)
                    }
                }
            } catch (e: Exception) {
                FirebaseCrashlytics.getInstance().recordException(e)
            }
        }
    }
}

    
	

well,仅查看enter image description herepartitionContainer

而不称为

addViewenter image description here, JVM无法回收对象。

如果不断地添加视图,则记忆使用墙继续增加。
    如果您在其他函数中调用
  1. removeView

    ,您是否拨打了exoplayer.release()和webview.destory(),nath callremoveView??

  2. 我无法在图片中键入tonghound
  3. ,您可以添加应用程序启动内存使用图片吗?

android webview mqtt android-glide exoplayer
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.