JS: Garbage Collection – Performance Driven Development – What is it?



JS: Garbage Collection – Performance Driven Development – What is it?

0 0


gc-talk


On Github TeeBrysiewicz / gc-talk

JS: Garbage Collection

Performance Driven Development

Created by Tobias Brysiewicz / @tbrysiewicz

Garbage Collection?

Garbage Collector?

GC?

What is it?

It is how memory is released automatically based on accurately finding unneeded memory using a mark-and-sweep algorithm.

Exhibit A

So what?

a.k.a. LAG

Because nothing good ever came out of lag.

Except leading in Gunz.

Example One

var another = null;
function test() {
    var str = 'A string I am';
    another = str;
}
    
test();
					

Example Two

"delete" fails to actually delete.

var m = 'test';
delete m; 
m === 'test'; // true - oops, still a value
						

Example Two Fix

The Garbage Collector will collect null.

var m = 'test';
m = null;
m === 'test'; // false
						

Contained Properties

var s = { data: 'test' };
s.data = null;  
s = null;  

						

Google Says

"...memory which is no longer needed is not released."

Our Memory Leak

var obj;
var leakMemory = function() {
	obj = document.getElementById("DivElement");
	obj.expandoProperty = obj;
	obj.bigString = new Array(1000).join(new Array(2000).join("XXXXX"));
};
						

Few Tips:

Open Chrome Dev Tools Timeline: Detecting GC Timeline: Base Memory

THE END

Thank You

- teebrysiewicz.github.io - @tbrysiewicz

JS: Garbage Collection Performance Driven Development Created by Tobias Brysiewicz / @tbrysiewicz