package com.njnu.kai.practice.memory;


import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.support.v4.content.LocalBroadcastManager;
import android.view.View;
import android.widget.ImageView;

import com.njnu.kai.support.BaseTestListFragment;
import com.njnu.kai.support.TestFunction;

/**
 * @author hongkai.qian
 * @version 1.0.0
 * @since 17/3/17
 */
public class MemoryLeakFragment extends BaseTestListFragment {

    @TestFunction("创建1000个ImageView")
    public void onTest01() {
        for (int i = 0; i < 1000; i++) {
            View view = new ImageView(getActivity());
        }
    }

    @TestFunction("创建1000个ImageView,主动gc")
    public void onTest02() {
        for (int i = 0; i < 1000; i++) {
            View view = new ImageView(getActivity());
        }
        System.gc();// 4.x可以 art不一定 5.x不一定 仅标记
        System.runFinalization();
//        Runtime.getRuntime().gc();
    }

    @TestFunction("register Receiver but not unregister")
    public void onTest03() {
        LocalBroadcastManager.getInstance(getContext()).registerReceiver(new TestBroadcastReceiver(), new IntentFilter("xxxxAction"));
        //如果TestBroadcastReceiver是静态类,不会泄露MemoryLeakFragment本身,receiveRecord持有TestBroadcastReceiver
        //但如果不是静态类, 则不会泄露MemoryLeakFragment也会被receiver持有
    }

    private class TestBroadcastReceiver extends BroadcastReceiver {
        @Override
        public void onReceive(Context context, Intent intent) {

        }
    }
}

@@ -33,16 +33,52 @@
 mory;%0A%0A%0A
+import android.app.ActivityManager;%0A
 import a
@@ -107,24 +107,24 @@
 stReceiver;%0A
-
 import andro
@@ -207,24 +207,50 @@
 tentFilter;%0A
+import android.os.Bundle;%0A
 import andro
@@ -400,24 +400,24 @@
 stFragment;%0A
-
 import com.n
@@ -447,16 +447,42 @@
 ction;%0A%0A
+import java.util.Locale;%0A%0A
 /**%0A * @
@@ -1468,24 +1468,559 @@
 er%E6%8C%81%E6%9C%89%0A    %7D%0A%0A
+    @Override%0A    public void onViewCreated(View view, Bundle savedInstanceState) %7B%0A        super.onViewCreated(view, savedInstanceState);%0A        ActivityManager activityManager = (ActivityManager) getContext().getSystemService(Context.ACTIVITY_SERVICE);%0A%0A        int memoryClass = activityManager.getMemoryClass();%0A        int largeMemoryClass = activityManager.getLargeMemoryClass();%0A        setResult(String.format(Locale.getDefault(), %22memory=%25d largeMemory=%25d%22, memoryClass, largeMemoryClass));%0A        //mi 3s : 192 384%0A%0A    %7D%0A%0A
     private 

test memory and large memory size