鍍金池/ 教程/ Android/ Memory leak專題
Launch mode 和 Intent flags專題
Canvas & Drawables
UTAustinX_UT.9.01x: Effective Thinking Through Mathematics
《JavaScript 語言精粹》
Memory leak專題
React基礎(chǔ)
《Test Driven Development: By Example》一書
Developer tools
安卓開發(fā)技能樹
<a rel="nofollow" href="https://mp.weixin.qq.com/s?__biz=MzA3NDM
Best Practices for Interaction and Engagement
各個安卓版本引入的主要新特性
Building Apps with Connectivity &amp; the Cloud
List.toArray()再強(qiáng)轉(zhuǎn)是一定會失敗的
深入Android frameworks
Google dev 100 days系列視頻
Building Apps with Contacts &amp; Sign-In
關(guān)系型數(shù)據(jù)庫設(shè)計范式
《App研發(fā)錄》一書
REST API設(shè)計
Google IO 2015摘要
自定義View/ViewGroup以及高性能實現(xiàn)自定義UI
安卓系統(tǒng)點擊事件處理
《50 Android Hacks》一書
Building Apps with Content Sharing
Flux基礎(chǔ)
<a rel="nofollow" href="http://developer.android.com/training/in
依賴注入(以Dagger 2為例)
Java同步機(jī)制
Java對象內(nèi)存的使用情況
JSR133(Java memory model)
Google官方Material Design手冊(<a rel="nofollow" href="http://develop
Futurice公司安卓團(tuán)隊的建議
安卓性能優(yōu)化
  • 1.
Best Practices for Performance
<a rel="nofollow" href="http://www.vogella.com/tutorials/Android
<a rel="nofollow" href="http://blog.danlew.net/2014/11/19/styles
Handling Runtime Changes
<a rel="nofollow" href="http://www.vogella.com/tutorials/Android
Building Apps with Graphics &amp; Animation
<a rel="nofollow" href="http://tools.android.com/tech-docs/new-b
Android項目架構(gòu)
MVP(Model-View-Presenter)模式
<a rel="nofollow" href="http://www.infoq.com/cn/es6-in-depth/"">
《Android源碼設(shè)計模式解析與實戰(zhàn)》一書
Rx在Android中的最佳實踐
函數(shù)調(diào)用時,傳遞參數(shù)應(yīng)該是不可變的(Immutable)
ProGuard
面向?qū)ο罅笤瓌t(SOLID+)
深入理解Java虛擬機(jī)
深入Java深淺拷貝、immutable、unmodifiable
Best Practices for User Input
UI上的一些高效方式/最佳實踐
<a rel="nofollow" href="https://blog.stylingandroid.com/ripples-
Best Practices for User Interface
安卓測試驅(qū)動開發(fā)/安卓測試驗證
暗時間:學(xué)會正確思考
技術(shù)筆記
Aspect Oriented Programming(AOP)
Best Practices for Background Jobs
安卓系統(tǒng)動效專題
Feed系統(tǒng)的設(shè)計
Data binding(MVVM,Model-View-ViewModel)
Effective Java一書筆記
<a rel="nofollow" href="http://developer.android.com/training/in
Rx (Reactive eXtention)
MultiDex專題
一些很棒的點子
WebRTC

Memory leak專題

  • 神器:LeakCanary,memory leak檢測工具;

Hanlder、Runnable、Thread的非靜態(tài)內(nèi)部類、匿名類,都會持有外部類的強(qiáng)引用,都可能造成內(nèi)存泄漏;

  • Java的非靜態(tài)內(nèi)部類、匿名類,會持有外部類的強(qiáng)引用,靜態(tài)的不會持有;對于Activity/Fragment內(nèi)定義的Handler/Runnable,是最容易因此導(dǎo)致內(nèi)存泄漏的,因為它們可能會postDelayed,從而導(dǎo)致Activity/Fragment及其內(nèi)部的資源無法GC;推薦做法是定義靜態(tài)內(nèi)部類/靜態(tài)匿名成員,訪問外部類的成員和方法通過WeakRefrence實現(xiàn);
  • WeakRefrence需要在內(nèi)部類內(nèi)創(chuàng)建才符合其語義?

Prior to Android Lollipop, alert dialogs may cause memory leaks in your Android apps.

  • 考慮以下代碼
    while (true) {
      MyMessage msg = queue.take(); // might block
      System.out.println("Received: " + msg);
    }

    msg對象是棧上的局部變量,每次循環(huán)都將會重寫,一旦被重寫,上一次循環(huán)的msg引用指向的對象將不再被其引用;但是在Dalvik虛擬機(jī)的實現(xiàn)中,如果queue.take()阻塞了,那么本次循環(huán)的msg未被賦值,則上次的msg的引用將不會被清除,

  • HandlerThread
    for (;;) {
      Message msg = queue.next(); // might block
      if (msg == null) {
        return;
      }
      msg.target.dispatchMessage(msg);
      msg.recycleUnchecked();
    }

    msg每次循環(huán)的后面都被recycle了(清空了內(nèi)容),所以泄漏的僅僅是一個空的msg對象,影響不大(LeakCanary將默認(rèn)忽略Message對象的泄漏)。

  • 遇上AlertDialog
    new AlertDialog.Builder(this)
      .setPositiveButton("Baguette", new DialogInterface.OnClickListener() {
        @Override public void onClick(DialogInterface dialog, int which) {
          MyActivity.this.makeBread();
        }
      })
      .show();

    DialogInterface.OnClickListener的匿名實現(xiàn)類持有了MainActivity的強(qiáng)引用;而在AlertDialog的實現(xiàn)中,OnClickListener類將被包裝在一個Message對象中,而且這個Message會在其內(nèi)部被復(fù)制一份,兩份Message中只有一個被recycle,另一個(OnClickListener的成員變量引用的Message對象)將會leak!

  • 解決辦法
    • ART VM(>=5.0),JVM不存在此問題
    • Message對象的泄漏無法避免,但是如果僅僅是一個空的Message對象,而且將被放入對象池作為后用,是沒有問題的
    • DialogInterface.OnClickListener對象不持有外部類的強(qiáng)引用:static類實現(xiàn);DetachableClickListener(監(jiān)聽窗口解除事件,手動釋放引用);
    • 當(dāng)worker thread空閑后,向HandlerThread發(fā)送一個空的消息,解除上一個Message的泄漏