I basically have an object, which I call two functions from, and three functions.
function func1()
M.mfunc1( 'updateSomething' );
// do some stuff
M.mfunc2();
}
function func2 () {
M.mfunc1 ( 'hitSomething' );
// does something but line is stable
M.mfunc2();
}
function func3 () {
M.mfunc1 ( 'doesSoemthing' );
//does nothing, but causes memory to grow
M.mfunc2();
}
M.mfunc1 = function ( name ) {
// code is all commented out
}
M.mfunc2 = function () {
// code is all commented out
}
func1n is called on a main loop using setTimeout. When using Chromes’s Dev Tools on the Timeline watching Memory, memory suddenly grows on the call of func3, but if I comment out the M calls, it stays stable. I resorted to commenting everything out of M.mfunc1 and M.mfunc2 and by just calling it a lone, it causes memory usage to grow.
Now can someone explain that to me?
Update: I made my code more like what it really is.
Update 2: Since the example code I gave doesn’t seem to be the problem, here’s a link to all the code: http://test.startailpro.co.uk/breaking/
The functions are update, updateDirection, hitBlock, doesBall_hitBlock, MEMORY.deep and MEMORY.rise.
In the end what I did was rewrite the whole code. I actually managed to write the whole thing without using objects, except on load. I still don’t know what’s wrong from the original code, but I am now better able to understand memory is used an grows.
Memory being allocated
I would recommend being careful what framework you choose. I found in jQuery that events causes memory growth. Since your receiving an object and an object is being generated for the event this not be a issue. Although, I am under the assumption that event objects are native and have been optimised so memory growth is not an issue. Again, be careful of frameworks.