ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • Memory Management
    개발/Javascript 2022. 6. 5. 14:27

    *복습 자료라서 뻔한 내용은 생략

     

     

    Summary.

     

     

    1. 메모리 할당: 초기화 시 / 함수호출 시 / 복사 시, 등

    var n = 123; // allocates memory for a number
    var s = 'azerty'; // allocates memory for a string
    
    var o = {
      a: 1,
      b: null
    }; // allocates memory for an object and contained values
    
    // (like object) allocates memory for the array and
    // contained values
    var a = [1, null, 'abra'];
    
    function f(a) {
      return a + 2;
    } // allocates a function (which is a callable object)
    
    // function expressions also allocate an object
    someElement.addEventListener('click', function() {
      someElement.style.backgroundColor = 'blue';
    }, false);
    var d = new Date(); // allocates a Date object
    var e = document.createElement('div'); // allocates a DOM element
    var s = 'azerty';
    var s2 = s.substr(0, 3); // s2 is a new string
    // Since strings are immutable values,
    // JavaScript may decide to not allocate memory,
    // but just store the [0, 3] range.
    
    var a = ['ouais ouais', 'nan nan'];
    var a2 = ['generation', 'nan nan'];
    var a3 = a.concat(a2);
    // new array with 4 elements being
    // the concatenation of a and a2 elements.

     

    2. Garbage Collection 알고리즘은 Reference Counting -> Mark & Sweep 으로 변경된지 오래

        + Circular Reference에 대한 해결책으로 대두된 것이 Mark & Sweep

        + generational/incremental/concurrent/parallel garbage collection, 등, 개선돼옴

        + no longer needed 가 아닌 no longer reachable 개념으로 접근

        + 직접 메모리 할당을 해제하는 기능은 2019년 이후부터 제거됨 (아마 Risky 해서?)

        + node.js는 메모리 할당/해제 디버깅 기능을 지원 (Web Browser 환경에서는 지원 안함)

     

     

    Reference.

    '개발 > Javascript' 카테고리의 다른 글

    Module System  (0) 2022.06.05
    Prototype Chain  (0) 2022.06.05
    Array & Loop  (0) 2022.06.04
    Type  (0) 2022.06.04
    Function  (0) 2022.06.03
Designed by Tistory.