How to find out IDs or names of preloaded system drawables (bitmaps) from memory dump

后端 未结 3 1783
滥情空心
滥情空心 2021-02-10 04:45

I\'m analyzing memory usage of our app, and has found strange Drawables, which constantly \"eats\" few megabytes of heap. Here are few screenshots from MAT:

相关标签:
3条回答
  • 2021-02-10 05:00

    I would guess they stay in memory because they are the default backgrounds for activities. Try specifying a different background in your theme and see if they are still there.

    0 讨论(0)
  • 2021-02-10 05:12

    This picture from android.jar, which you have to include into your project. There are two squares with the vertical gradient. The first - from 0x000000 to 0x272d33, the second - from 0xe8e8e8 to 0xfafafa. You can find them in android.jar/res/drawable-nodpi/background_holo_dark.png and background_holo_light.png. Of course, you can get different results depending on your Android SDK version.

    0 讨论(0)
  • 2021-02-10 05:17

    The preloaded drawables are loaded by Zygote.

    ZygoteInit#preloadResources()

        /**
     * Load in commonly used resources, so they can be shared across
     * processes.
     *
     * These tend to be a few Kbytes, but are frequently in the 20-40K
     * range, and occasionally even larger.
     */
    private static void preloadResources() {
        final VMRuntime runtime = VMRuntime.getRuntime();
    
        try {
            mResources = Resources.getSystem();
            mResources.startPreloading();
            if (PRELOAD_RESOURCES) {
                Log.i(TAG, "Preloading resources...");
    
                long startTime = SystemClock.uptimeMillis();
                TypedArray ar = mResources.obtainTypedArray(
                        com.android.internal.R.array.preloaded_drawables);
                int N = preloadDrawables(runtime, ar);
                ar.recycle();
                Log.i(TAG, "...preloaded " + N + " resources in "
                        + (SystemClock.uptimeMillis()-startTime) + "ms.");
    
    
                startTime = SystemClock.uptimeMillis();
                ar = mResources.obtainTypedArray(
                        com.android.internal.R.array.preloaded_color_state_lists);
                N = preloadColorStateLists(runtime, ar);
                ar.recycle();
                Log.i(TAG, "...preloaded " + N + " resources in "
                        + (SystemClock.uptimeMillis()-startTime) + "ms.");
            }
            mResources.finishPreloading();
        } catch (RuntimeException e) {
            Log.w(TAG, "Failure preloading resources", e);
        }
    }
    

    You see, the preloaded drawables are com.android.internal.R.array.preloaded_drawables

    0 讨论(0)
提交回复
热议问题