Upgrade to Pro — share decks privately, control downloads, hide ads and more …

javascriptのGC入門

 javascriptのGC入門

javascriptのGCの特徴やどのように動作するかの解説

More Decks by Taketoshi Aono(青野健利 a.k.a brn)

Other Decks in Programming

Transcript

  1. javascript Garbage Collector Overview

  2. せ⵸: @brn (ꫬꅿ⨳ⵃ) 耵噟: ؿٗٝزؒٝسؒٝآص،٥iOSؒٝآص، ⠓爡: Cyberagent ،سذؙأةآؔRightSegment٥AI Messenger ـؚٗ:

    http://abcdef.gets.b6n.ch/
  3. What is Garbage Collector? Garbage Collectorהכծفؚٗٓي⚥חⶴ׶䔲ג׵׸׋ؔـآؙؑزך 灶唱׾遤ְծًٌٔ걄㚖׾然⥂׃湫ׅ׮ךկ

  4. What is Garbage Collector? var x = { a: 1,

    b: 2 } Object Field a Field b Other Objects Heap ًٌٔⶴ׶䔲ג
  5. What is Heap? Stack ꟼ侧 = ⠓陽 Heap مٙ؎زن٦س 陽✲ꐮ

  6. What is Heap? Stackכꟼ侧⽃⡘דⶴ׶䔲ג׵׸ծꟼ侧ָ穄✪ׅ׷ה荈⹛ד灶唱ׁ׸ג׃ת ֲկ Heapכفؚٗٓيָ㶷㖈׃גְ׷꟦כ䌢ח⦼׾⥂㶷׃גֶֽ׷կ javascriptכ䌢חHeapח⦼׾ⶴ׶䔲ג׷♳ծStackכ湫䱸ׁ׻׸זְךדծ 罋ִ׷䗳銲כזְկ

  7. What is Heap? Stack Process Stack Heap Process Stack Heap

    Process 饯⹛儗 㹋遤⚥ 㹋遤⚥(㣐ꆀⶴ׶䔲ג)
  8. What is Heap? OUT OF MEMORY

  9. Garbage Collector 㟓ִֺׅ׋Heapכ铩ַָ䰾ꤐ׃זֽ׸לְֽזְկ ׉׸׾׃גֻ׸׷ךָ Garbage Collector 

  10. Garbage Collector  ًٌٔⶴ׶䔲ג var x = {} var y

    = {} Heap Global x y
  11. Garbage Collector  Garbage CollectorָHeapךⵋ麦〳腉זؔـآؙؑزחو٦ؙ׾➰ֽ׷ Heap Global x y

  12. Garbage Collector  ًٌٔⶴ׶䔲ג var x = {} var y

    = {} y = null Heap Global x y
  13. Garbage Collector  Garbage CollectorָHeapךⵋ麦〳腉זؔـآؙؑزחو٦ؙ׾➰ֽ׷ Heap Global x y

  14. Garbage Collector  ًٌٔⶴ׶䔲ג var x = {}; var y

    = {x: x}; x = null y.x = null Heap Global x y
  15. Garbage Collector  Garbage CollectorָHeapךⵋ麦〳腉זؔـآؙؑزחو٦ؙ׾➰ֽ׷ Heap Global x y

  16. Garbage Collector  ًٌٔⶴ׶䔲ג var x = {}; var y

    = {x: x}; x = null y = null Heap Global x y
  17. Garbage Collector  Garbage CollectorָHeapךⵋ麦〳腉זؔـآؙؑزחو٦ؙ׾➰ֽ׷ Heap Global x y

  18. Garbage Collector  Heap Global x y Garbage CollectorָHeapךو٦ָؙזְؔـآؙؑز׾灶唱ׅ׷

  19. Garbage Collector  Garbage CollectorָHeapךⵋ麦〳腉זؔـآؙؑز׾و٦ؙ و و٦ ٦ؙ ؙؿ ؿؑ

    ؑ؎ ؎ؤ ؤ(Mark Phase) Garbage CollectorָHeapךⵋ麦♶〳腉זؔـآؙؑز׾灶唱 أ أؐ ؐ؍ ؍٦ ٦ف فؿ ؿؑ ؑ؎ ؎ؤ ؤ(Sweep Phase)
  20. Garbage Collector  ֿ׸ָ و و٦ ٦ؙ ؙ، ،ٝ ٝس

    سأ أؐ ؐ؍ ؍٦ ٦ف ف(Mark And Sweep) הְֲ،ٕ؞ٔؤيדׅկ
  21. Garbage Collector  ׋׌׃ծֿךMarkPhaseהSweepPhaseכ ؔـآؙؑزךخٔ٦׾׋ו׷ךדծفؚٗٓيך؟؎ؤח״׏גכծ ꬊ䌢ח頾蚚ַַָ׶תׅկ ׉ך׋׭ծ植㖈ךـٓؐؠדכֿ׸׵ך⹛⡲׾㼰׃בא遤ֲծ ؎ ؎ٝ ؙٝ

    ؙٔ ًٔ ًٝ ٝة ةٕ ٕGC(Incremental GC) הㄎל׸׷䩛岀ָ欽ְ׵׸גְתׅկ ׍ז׫חMark&Sweepדفؚٗٓيָ⨡姺׃ג׃תֲֿה׾ Stop the world הㄎןתׅկ
  22. Incremental Garbage Collection Garbage CollectorָHeapךⵋ麦〳腉זؔـآؙؑزחو٦ؙ׾➰ֽ׷ Heap Global x y 中断

  23. Incremental Garbage Collection Garbage CollectorָHeapךو٦ָؙזְؔـآؙؑز׾灶唱ׅ׷ Heap Global x y 中断

  24. Incremental Garbage Collection Incremental GCכMark Phaseך鷿⚥ד⿫撑ָ㢌⻉ׅ׷〳腉䚍ָ֮׷׋׭ծ ٓ؎زغٔ،(WriteBarrier) ה״ל׸׷ծ⿫撑ָ剅ֹ㢌׻׏׋ֿה׾嗚濼ׅ׷➬穈׫ָ䗳銲חז׶תׅկ

  25. Incremental Garbage Collection var x = {} var y =

    {} y.x = x; Object(x) Heap Object(y) WRITED
  26. Incremental Garbage Collection Garbage CollectorכWriteBarrierח״׏גو٦ׁؙ׸׋ؔـآؙؑزכ灶唱דֹזְ Heap Global x y 中断

    WRITED 削除しない
  27. Incremental Garbage Collection Incremental GCכفؚٗٓيך⨡姺儗꟦׾䫇ִ׷׋׭ך،ٕ؞ٔؤيד֮׶ծ GC荈⡤ך儗꟦כⰋ⡤涸ח⠼ןתׅկ ָծ⡤䠬ך鸞䏝כֶ׉׵ֻ傍ֻ䠬ׄתׅկ

  28. Summary ֿך项俱כꬊ䌢ח邌꬗涸ז铡僇דׅկ 劤勻GCכꬊ䌢ח醱꧟דծ➂겲ך〝兰ך穠兪הד׮ְֲ״ֲז׮ךזךדծ 莆㄂ָ֮׷倯כ׮׏ה帾ֻ锃ץג׫גֻ׌ְׁկ ֮הծhttps://github.com/authorNari/minigcח449遤ךminiGCהְֲꬊ䌢؝ٝ ػؙزז㹋鄲ָ֮׷ךדծ鋅ג׫גֻ׌ְׁկ ֿ׍׵ך ؖك٦آ؝ؙٖءّٝך،ٕ؞ٔؤيה㹋鄲הְֲ劤ֶָׅׅ׭דׅկ https://www.amazon.co.jp/%E3%82%AC%E3%83%99%E3%83%BC%E3%82%B8%E3%82%B3%E3%83%AC %E3%82%AF%E3%82%B7%E3%83%A7%E3%83%B3%E3%81%AE%E3%82%A2%E3%83%AB

    %E3%82%B4%E3%83%AA%E3%82%BA%E3%83%A0%E3%81%A8%E5%AE%9F%E8%A3%85-%E4%B8%AD%E6%9D %91-%E6%88%90%E6%B4%8B/dp/4798025623
  29. ׀ ׀幠 幠耮 耮֮ ֮׶ ׶ָ ָה הֲ ֲ׀ ׀ׂ

    ְׂ ְת ת׃ ׃׋ ׋ 