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

后端 未结 3 1785
滥情空心
滥情空心 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: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

提交回复
热议问题