在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 教程/ Android/ Java對象內(nèi)存的使用情況
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()再強轉(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同步機制
Java對象內(nèi)存的使用情況
JSR133(Java memory model)
Google官方Material Design手冊(<a rel="nofollow" href="http://develop
Futurice公司安卓團隊的建議
安卓性能優(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虛擬機
深入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

Java對象內(nèi)存的使用情況

一般情況

  • primitive types
    http://wiki.jikexueyuan.com/project/notes/images/java_primitive_types_mem_usage.png" alt="java_primitive_types_mem_usage.png" />
  • Object overhead for "housekeeping" information
    recording an object's class, ID and status flags such as whether the object is currently reachable, currently synchronization-locked etc.
    Hotspot JVM:
    • Object類實例:8字節(jié);
    • Object類實例數(shù)組:12字節(jié),比Object類實例多了個length域;
  • Object size granularity
    為了便于尋址,對象內(nèi)存會8字節(jié)對齊;
    例子:
    • Object類實例8字節(jié);
    • 只有一個boolean成員的類對象,16字節(jié),有8個boolean成員的類對象,16字節(jié);
    • 有兩個long成員、三個int成員、一個boolean成員的類對象,40字節(jié);

數(shù)組

  • object header:12個字節(jié),多了一個length域
  • 一維數(shù)組,數(shù)據(jù)區(qū)域,length * sizeof(element),此外,對于object是保存的引用,為4字節(jié)
  • 二維數(shù)組,每一行都是一個數(shù)組,故每一行都有object的開銷
  • 例子:10*10 int二維數(shù)組:
    • 外層header:12字節(jié)
    • 外層數(shù)據(jù)(10個引用):10*4=40字節(jié),加上padding,共56字節(jié)
    • 內(nèi)層每一行,header12字節(jié)
    • 內(nèi)層每一行,數(shù)據(jù)10*4=40字節(jié),加上padding,每一行共56字節(jié)
    • 總共56*11=616字節(jié)
  • 更多維的數(shù)組邏輯一致

String

  • 一個String對象實際上包含了不止一個對象
  • java的char占兩個字節(jié)
  • Minimum String memory usage (bytes) = 8 (int) ((((num chars) 2) + 45) / 8)
  • String對象包含:char數(shù)組,offset,length,hashcode這四部分內(nèi)容
  • 空String對象占用內(nèi)存:8(header) + 3*4(上述三個int域) + 4(char數(shù)組引用) + 12(空char數(shù)組header) + 4(char數(shù)組padding) = 40字節(jié)
  • 包含17個字符的String:24 + (12 + 17*2 + 2) = 72字節(jié)
  • substring使用時的trick
    • 如果原string和substring都會被使用,則節(jié)省了內(nèi)存
    • 如果原string不再被使用,有可能就會浪費內(nèi)存
    • 例如:
      原有的char數(shù)組并不會被回收,但是只使用了其中的一部分:
      String str = "Some longish string...";
      str = str.substring(5, 4);

      原有的char數(shù)據(jù)將來會被gc,避免了內(nèi)存浪費:

      String str = "Some longish string...";
      str = new String(str.substring(5, 4));

string buffers

StringBuffer、StringBuilder等
header: 8字節(jié);length,char數(shù)組引用;底層char數(shù)組所占內(nèi)存;
假設(shè)初始容量為16的string buffer:16 + 12 + 16*2 + 4 = 64字節(jié)
擴容策略是每次倍增容量

減少String占用的內(nèi)存

  • 通常不需要,只有確定String占用了太多內(nèi)存后才有必要。
  • 一下情形并不需要String,有更節(jié)省內(nèi)存的CharSequence實現(xiàn)。
    • storing the string in memory;
    • printing out the string or writing it to a stream;
    • retrieving individual characters/substrings from the string;
    • performing matches against regular expressions.
  • 不使用String的優(yōu)化方案:
    • 使用string buffer,通過trimToSize()可以至少比String少8字節(jié)
    • 只用來保存ASCII字符,使用byte[]更高效,或自行實現(xiàn)CharSequence接口,使用更節(jié)省內(nèi)存的底層結(jié)構(gòu),只在最后需要使用的時候轉(zhuǎn)化為String
  • 必須使用String時的優(yōu)化方案
    • 創(chuàng)建substring時,如果原string不再使用,那應(yīng)該通過new一個新的String,而不是直接賦值給原引用
    • 當有很多內(nèi)容相同的String對象時,可以通過兩種方式節(jié)省內(nèi)存:
      • 將內(nèi)容定義為enum,使用時使用enum值
      • 規(guī)范化:使用String.intern()方法;使用HashMap等集合;
        String employeeStatus = rs.getString(2);
        employeeStatus = employeeStatus.intern();
      • intern():將String的內(nèi)容放到JVM的string pool中,此過程不可逆,很可能會導(dǎo)致內(nèi)存泄漏;因此只有確定內(nèi)容只有很少的幾種時才可行;