This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
chrome --enable-memory-info |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
window.performance.memory.totalJSHeapSize; // currently used heap memory | |
window.performance.memory.usedJSHeapSize; // total heap memory |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// declare bullet pools | |
var activeBullets = []; | |
var bulletPool = []; | |
// construct some bullets ready for use | |
for (var i=0; i < 20; i++) | |
bulletPool.push( new Bullet() ); | |
// a constructor/factory function | |
function getNewBullet() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var b = new Bullet(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var b = getNewBullet(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (bullet.collidingWith(enemyShip)) // boom! | |
freeBullet(bullet); // return it to the pool |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (bullet.collidingWith(enemyShip)) // boom! | |
freeBullet(bullet); // return it to the pool |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getNewBullet(x, y) | |
{ | |
// ... previous code | |
// initialize the bullet | |
b.x = x; | |
b.y = y; | |
b.state = NORMAL; | |
return b; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
git clone https://github.com/playcraft/gamecore.js.git |