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. What is Garbage Collector? var x = { a: 1,

    b: 2 } Object Field a Field b Other Objects Heap ًٌٔⶴ׶䔲ג
  2. What is Heap? Stack Process Stack Heap Process Stack Heap

    Process 饯⹛儗 㹋遤⚥ 㹋遤⚥(㣐ꆀⶴ׶䔲ג)
  3. Garbage Collector  ًٌٔⶴ׶䔲ג var x = {}; var y

    = {x: x}; x = null y.x = null Heap Global x y
  4. Garbage Collector  ًٌٔⶴ׶䔲ג var x = {}; var y

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

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

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

    ؙٔ ًٔ ًٝ ٝة ةٕ ٕGC(Incremental GC) הㄎל׸׷䩛岀ָ欽ְ׵׸גְתׅկ ׍ז׫חMark&Sweepדفؚٗٓيָ⨡姺׃ג׃תֲֿה׾ Stop the world הㄎןתׅկ
  8. Incremental Garbage Collection var x = {} var y =

    {} y.x = x; Object(x) Heap Object(y) WRITED