Coder Social home page Coder Social logo

leakcanary-for-eclipse's Introduction

LeakCanary For Eclipse

该项目是从LeakCanary移植到Eclipse的实现版,原始代码是从这里获得,并进行了一些修改。用了这个项目就可以很方便的找到内存泄漏问题啦,摆脱难用的MAT吧!

使用

  1. 将leakcanary-lib导入eclipse;
  2. 你的项目引用leakcanary工程;
  3. 在AndroidManifest.xml中添加如下:
<!-- 写权限-->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<!-- 相关的服务与Activity  -->
<activity android:name="com.squareup.leakcanary.internal.DisplayLeakActivity"
            android:enabled="false"
            android:icon="@drawable/__leak_canary_icon"
            android:label="@string/__leak_canary_display_activity_label"
            android:taskAffinity="com.squareup.leakcanary"
            android:theme="@style/__LeakCanary.Base" >
        </activity>

<service
android:name="com.squareup.leakcanary.internal.HeapAnalyzerService"
        android:enabled="false"
        android:process=":leakcanary" />
<service
       android:name="com.squareup.leakcanary.DisplayLeakService"
       android:enabled="false" />
  1. 创建一个Application子类,并且将它设置为应用的Application
public class MyApplication extends Application {
    private RefWatcher mRefWatcher;

    @Override
    public void onCreate() {
        super.onCreate();

        mRefWatcher = LeakCanaryWrapper.install(this, BuildConfig.DEBUG);
    }

    public RefWatcher getRefWatcher() {
        return mRefWatcher;
    }
}

然后在AndroidManifest.xml中设置application:

    <application
        android:name="com.leakcanary.demo.MyApplication"
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        // 省略
    </application/>
  1. 运行程序即可检测内存泄漏。

如果发生内存泄漏,那么则会在Log中输入相关错误信息:

上述信息很全面,第一行表示在com.leakcanary.demo中发生内存泄漏,泄漏的对象是com.leakcanary.demo.OtherActivity,持有它的是com.leakcanary.demo.ActivityManager.sInstance对象。

其他使用均与LeakCanary相似,可查看LeakCanary的相关资料。

leakcanary-for-eclipse's People

Contributors

hehonghui avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

leakcanary-for-eclipse's Issues

你的这个项目有崩溃

07-29 22:23:57.818: E/vz(5269): unRigistActivity com.leakcanary.demo.MainActivity@dee8feb
07-29 22:23:59.120: E/AndroidRuntime(5308): FATAL EXCEPTION: IntentService[HeapAnalyzerService]
07-29 22:23:59.120: E/AndroidRuntime(5308): Process: com.leakcanary.demo:leakcanary, PID: 5308
07-29 22:23:59.120: E/AndroidRuntime(5308): java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference
07-29 22:23:59.120: E/AndroidRuntime(5308): at com.squareup.leakcanary.HeapAnalyzer.findLeakingReference(HeapAnalyzer.java:154)
07-29 22:23:59.120: E/AndroidRuntime(5308): at com.squareup.leakcanary.HeapAnalyzer.checkForLeak(HeapAnalyzer.java:89)
07-29 22:23:59.120: E/AndroidRuntime(5308): at com.squareup.leakcanary.internal.HeapAnalyzerService.onHandleIntent(HeapAnalyzerService.java:57)
07-29 22:23:59.120: E/AndroidRuntime(5308): at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:66)
07-29 22:23:59.120: E/AndroidRuntime(5308): at android.os.Handler.dispatchMessage(Handler.java:102)
07-29 22:23:59.120: E/AndroidRuntime(5308): at android.os.Looper.loop(Looper.java:148)
07-29 22:23:59.120: E/AndroidRuntime(5308): at android.os.HandlerThread.run(HandlerThread.java:61)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.