Skip to content

Instantly share code, notes, and snippets.

View martinwells's full-sized avatar

Martin Wells martinwells

View GitHub Profile
function test()
{
var myString = 'a string';
}
test();
var another = null;
function test()
{
var str = 'A string I am';
another = str;
}
test();
// var b = null; // commented out now
function test()
{
var str = 'A string I am';
b = str; // oops, no var keyword means this is a global
}
test();
var s = { data: 'test' };
delete s.data;
var m = 'test';
delete m; // silently returns false (not allowed)
m === 'test'; // true - oops, still a value
var m = 'test';
m = null;
m === 'test'; // false
var s = { data: 'test' };
s.data = null; // not required
s = null; // this will automatically clear s.data as well
var newObject = new MyObject();
var lastUsedHeap = 0; // remember the heap size
function checkMemory()
{
// check if the heap size is this cycle is LESS than what we had last
// cycle; if so, then the garbage collector has kicked in
if (window.performance.memory.usedJSHeapSize < lastUsedHeap)
console.log('Garbage collected!');
lastUsedHeap = window.performance.memory.usedJSHeapSize;
do shell script
"\"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome\"
--enable-memory-info"