Author: Tran Tuan Quy
Date: Dec 28, 2017
Memory Life Cycle
Stack & Heap
Garbage Collection
Detect Memory Leak
Code smell for memory leak
Recap
//Allocate memory for creating an array
let students = ['John', 'David', 'Susan'];
//Change allocated memory
students[0] = 'Mary';
//Reclaim memory which is allocated at line 2
students = '';
Stack
Heap
an array
a date
a user
10
address of user
address of an array
address of date
function Student(name, dob) {
this.name = name;
this.dob = dob;
}
let bob = new Student('Bob', new Date('2009-01-01'));
function Student(name, dob) {
this.name = name;
this.dob = dob;
this.circularReference = this;
}
let bob = new Student('Bob', new Date('2009-01-01'));
function Student(name, dob) {
this.name = name;
this.dob = dob;
this.circularReference = this;
}
let bob = new Student('Bob', new Date('2009-01-01'));
//Release any reference to student object.
bob = null;
JavaScript Memory Management Masterclass