Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!

1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


Member Since 13 Jun 2001
Offline Last Active Today, 07:05 PM

#5142054 Javascript Memory leak

Posted by Madhed on 25 March 2014 - 12:42 PM



In javascript functions without a return statement return the value undefined.

#5142053 Javascript Memory leak

Posted by Madhed on 25 March 2014 - 12:40 PM

what is written to setInterval is  javascript code that gets executed every time the interval passes


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


since it is not an r value, it gets also executed-entered


I don't know why you are talking about r-values as this is javascript and not c++.

#5142046 Javascript Memory leak

Posted by Madhed on 25 March 2014 - 12:23 PM

The code is not creating a function every interval. It is passed once as an argument, that is all.

Furthermore your code is not correct. heavy() returns undefined. So you are actually calling setInterval(undefined, 1);



Apart from that typo, both snippets are identical except for the fact that in OP's code the function is anonymous whereas in yours it's stored in the variable heavy.

#5142029 Javascript Memory leak

Posted by Madhed on 25 March 2014 - 11:01 AM

it seems to leak according to chrome dev tools 


Is this the whole code? How did you come to the conclusion that it leaks memory? That simple snippet should not leak any memory.



I just tried it myself. Even with a completely empty interval function the memory usage increases continually until chrome decides it's enough and frees a large block. This is completely normal behaviour and does not mean there is a memory leak. If you let the profiler run long enough you will see some kind of zig-zag pattern where memory usage increases up to a certain point and then suddenly drops. Older browsers used to have problems detecting circular references and thus never freeing some memory but in my experience this is mostly fixed now.


It is nevertheless a good practice to keep memory allocations low so the GC doesn't have to do as much work because it can slow down your application a lot.

#5141742 Help with Smooth Gradient on Skydome

Posted by Madhed on 24 March 2014 - 11:32 AM

It may be that there are no dark lines in your gradent, and you've just got a 6bit-per-channel LCD and are seeing the mach bands illusion.


I can definitely see the bands on my LCD. Do you mean on your screen everything appears smooth, Hodgman?


Display quality aside, this is a general problem that can appear because in some situations 8 bit per channel still is not enough. Look for photoshop tutorials on how to get perfectly smooth gradients. If you have the banding problem, the only fix is to add dithering.




EDIT: ...or choose another color transition. Going from full blue to completely black gives you only 256 separate steps with a fairly high contrast. Spread that out over more than 256 pixels and you will get noticeable bands.

#5137877 No Low Level Programming is better ?, Please explain this then ?

Posted by Madhed on 10 March 2014 - 12:54 PM

My head hurts...

#5136792 Choosing a Fast WebGL Sprite Renderer

Posted by Madhed on 06 March 2014 - 07:55 AM

Have a look at Pixi.js. It supports WebGL and falls back automatically to canvas. And it's pretty fast.


Here's a Benchmark: http://www.goodboydigital.com/pixijs/bunnymark/

#5136396 Providing a download link

Posted by Madhed on 04 March 2014 - 04:50 PM

You can use the php function readfile() to output file contents into the http response stream.

You would use this on a url that the user can only access when logged in.

You should also use header() to set the correct mime type and tell the browser to prompt the user to download the file (instead of opening it in the browser)

header("Content-type: application/octet-stream"); 
header("Content-disposition: attachment; filename=test.zip");  

#5135408 How to get good fast?

Posted by Madhed on 28 February 2014 - 11:05 AM

There really is no shortcut to becoming good at anything,

Set yourself realistic goals and keep a steady but achievable curriculum.

Surround yourself with persons who are better than you at whatever you want to learn.

Never become satisfied with your skillset and don't snub your nose at other people's ideas.

After all, how are you going to learn something new when all you accept are opinions you already hold.

Throw yourself out there and don't be afraid of failure.

#5131331 Auto update systems - yes or no

Posted by Madhed on 14 February 2014 - 11:49 AM

I like when programs check for a new version on startup and give you the chance to automatically download and install or postpone the update.

#5131308 Is my code efficient?

Posted by Madhed on 14 February 2014 - 10:33 AM

You could eliminate the odd variable like this: 

do {
    // ...stuff
} while (max_stars % 2 == 0);

Then you also don't need to inlcude stdbool.h


I think the condition is pretty self explanatory. Alternatively you could factor this expression out into a function is_odd()


Also you probably want to check if max_stars is greater than zero.

#5129922 Thread-safe unique sequential index per class

Posted by Madhed on 08 February 2014 - 03:25 PM

The problem here is that in a multi threaded environment different classes could be assigned the same index, right?

So I guess the AtomicInteger wold be the right solution, no? Am I missing something?


Edit: Should have read the code first...


Edit2: What about static initialization blocks? I haven't done extensive java programming but they seem like a better solution. Initialization is done *once* the class is first loaded. They are thread safe.

#5129262 Alpha Blend in DirectX?

Posted by Madhed on 06 February 2014 - 03:36 AM

Disable z-writing when drawing the alpha shapes.

#5128189 How do I increment a shared pointer?

Posted by Madhed on 02 February 2014 - 10:41 AM

Well, there's shared_ptr::get which returns the underlying raw pointer.


So I guess you could do (didn't test this): i.get()[5] = 10;


But I suggest you don't use shared_ptr-to-array.

#5128181 How do I increment a shared pointer?

Posted by Madhed on 02 February 2014 - 10:27 AM

That's not possible.


What are you trying to accomplish?


Why don't you use a std::vector instead of a plain array? i.e a shared_ptr to a std::vector