Jump to content

  • Log In with Google      Sign In   
  • Create Account


tanzanite7

Member Since 20 Nov 2005
Offline Last Active Yesterday, 05:33 PM
-----

Posts I've Made

In Topic: Javascript Memory leak

26 March 2014 - 04:05 AM

biggrin.png, true that.

duty_calls.png

(sorry for being a jackass - i am just easily amused)

In Topic: Javascript Memory leak

26 March 2014 - 03:23 AM

anyway, it just looks stupid that the garbage collector have that zigzag pattern at all
 
what memory does it allocate ? it uses one global variable and that's all
I didn't even declare a new variable.
 
This is strange indeed

1. garbage source.

While your example program itself does not visibly generate garbage - there still are plenty of garbage sources, a'la: virtual machine interpreting the javascript, jit compilation, whatever other internal structs it needs to implement the used or assumed to be used functionality of javascript.

Case in point of a possible source: calling a function needs a local scope/closure to be created and destroyed (technically - a good jit optimizer under specific conditions can prevent it from using generic GC for cleanup).

2. zigzag pattern.

Garbage collection is an overhead (ie. in a sense no useful work is done - GC is hardly the goal of any program tongue.png ). Hence GC implementations avoid actually doing it if they do not need to do it (ie. there is plenty of free memory) - allowing memory usage to steadily grow till it finally decides to do the work causing a sudden drop in memory usage => zigzag.

edit:

it seems to leak according to chrome dev tools

I have not used chrome dev tools, but i guess you are misinterpreting what it tells you.

I don't think this is a case of circular dependencies or anything to do with DOM

Yep. However, memory is not free till GC tells so => every unused crumb of memory piles up over time till GC gets rid of them all, all at once.

is this normal in javascript ?

Yes. It is common in all languages that heavily use mark-and-sweep style GC, not just javascript.

One might have a leak problem if memory usage grows over GC cycles (ie zigzag bottom line keeps growing).

In Topic: Javascript Memory leak

25 March 2014 - 01:16 PM

/.../ and please explain me where I am wrong.

He already did:

What is "written" to setInterval is a reference to the function.


You have already stated a whole pile of nonsense, /.../

Except that his "pile of nonsense" is actually correct and your statements are not.

My guess is that you did not notice that the lambda function given to setInterval is not given as an string. This guess is also supported by the error you made in your example:

setInterval(heavy(), 1 ); // this is equal to: "setInterval(undefined, 1 )", given that heavy() returns "undefined".
instead of what you probably meant:
setInterval("heavy()", 1 );

In Topic: disable windows key - hook or message pump?

21 March 2014 - 01:04 AM

I have never found an alternative to keyboard hook - although i have never wanted to disable it per-se, just disable its usual function and make it available as a regular key for keybinds.

 

However, as frob mentioned - have an easy to access option for disabling the override.

 

OT: Similarily, might want to consider optionally disabling sticky keys etc whenever your game has focus (you can do that with SystemParametersInfo). Specifically: STICKYKEYS, TOGGLEKEYS and FILTERKEYS.


In Topic: Exactly what's the point of 'int32_t', etc.

19 March 2014 - 05:51 AM

Another thing int32_t family of types does is guarantee twos compliment arithmetic.

Really? I highly doubt that, can anyone confirm?

PARTNERS