2016-08-02 3 views
3

LeakCanaryを統合して、メモリリークの問題を解決するのに役立ちます。私たちは、私が削除されません静的参照を作成した権利をすべてのものを設定し、それを見てleakCanaryを告げていることを確認するために、内MainActivityLeakCanaryは意図的に追加したリークを捕まえません。私は何が欠けていますか?

Box box; 
    Cat schrod; 


@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

    box = new Box(); 
    schrod = new Cat(); 
    box.hiddenCat = schrod; 
    Docker.container = box; 
    Application.getRefWatcher().watch(schrod); 


    System.gc(); 
} 

public class Cat { 
} 

public class Box { 
     public Cat hiddenCat; 
} 

public class Docker { 
    public static Box container; 
} 

クラス

private static RefWatcher sRefWatcher; 

    @Override 
    public void onCreate() { 
     sRefWatcher = LeakCanary.install(this); 
    }  
    public static RefWatcher getRefWatcher() { 
     return sRefWatcher; 
    } 

build.gradleファイルにApplication

dependencies { 
     debugCompile 'com.squareup.leakcanary:leakcanary-android:1.3.1' 
     releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.3.1' 
} 

私は、schrodオブジェクトへの参照が残っていることを私に知らせることはできません。ことが起こる:あなたは(https://github.com/square/leakcanaryこのページGetting Startedガイドに記載されています):最新バージョンにbuild.gradle依存関係を更新する必要があります

答えて

1

debugCompile 'com.squareup.leakcanary:leakcanary-android:1.4-beta2' 
releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.4-beta2' 
testCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.4-beta2' 
+1

確かにそれを修正しました。 –

関連する問題