GPWiki.org
GPWiki.org
It is currently Sat May 25, 2013 1:45 am

All times are UTC




Post new topic Reply to topic  [ 9 posts ] 
Author Message
PostPosted: Mon Aug 15, 2011 7:53 am 
Shake'n'Baker
User avatar

Joined: Mon Jun 14, 2010 3:51 pm
Posts: 62
I am working on a project which works at 10 fps. Every time it repaints, it allocates more 4kb of memory.

Chrome has a function/button in its developer tools that allows me to manually collect garbage.
I am not aware if other browsers have this feature.

Is there a way to do this with JavaScript?


Top
 Profile  
 
PostPosted: Mon Aug 15, 2011 9:28 am 
Harmlessness does no harm
User avatar

Joined: Tue Sep 14, 2004 8:37 pm
Posts: 3810
Location: Ferriday, LA, US
Wait wait wait... are you saying that on every repaint, your script allocates 4kb *more* memory? As in it keep growing and growing? If so, the problem is your code. That said, garbage collection is automatic and handled by the browser.

Please post some of your code so we can get to the bottom of this.

_________________
What most people don't understand about "enlightenment" is that it is not an end-goal; but where you find yourself just before taking a new "first step."


Top
 Profile  
 
PostPosted: Mon Aug 15, 2011 1:14 pm 
Dexterous Droid
User avatar

Joined: Wed Aug 18, 2004 7:40 pm
Posts: 3735
Location: South Africa
You could reuse your objects instead of letting them get garbage collected. So set things to be inactive rather than deleting them. Then when something new gets spawned, reactivate and reinitialise one of the inactive objects.

Allocating 4kb more memory every repaint sounds high. But as long as it eventually gets garbage collected, maybe its not worth worrying about. It's only a serious problem if you've somehow created a memory leak, where that 4kb of allocated memory never gets garbage collected.

_________________
Whatever the mind can conceive and believe, it can achieve


Top
 Profile  
 
PostPosted: Mon Aug 15, 2011 1:21 pm 
Harmlessness does no harm
User avatar

Joined: Tue Sep 14, 2004 8:37 pm
Posts: 3810
Location: Ferriday, LA, US
IGTHORN wrote:
You could reuse your objects instead of letting them get garbage collected. So set things to be inactive rather than deleting them. Then when something new gets spawned, reactivate and reinitialise one of the inactive objects.

Allocating 4kb more memory every repaint sounds high. But as long as it eventually gets garbage collected, maybe its not worth worrying about. It's only a serious problem if you've somehow created a memory leak, where that 4kb of allocated memory never gets garbage collected.


Yeah, assuming he is using a canvas element, it would just be a matter of making one (or two if using a backbuffer) canvas element, and using that throughout the life of the script. For the vast majority of purposes, that would be fine... one would not need to worry about allocating and/or garbage-collecting such a thing.

Like I said, once we see code, we can see the issue. :)

_________________
What most people don't understand about "enlightenment" is that it is not an end-goal; but where you find yourself just before taking a new "first step."


Top
 Profile  
 
PostPosted: Mon Aug 15, 2011 1:49 pm 
Shake'n'Baker
User avatar

Joined: Mon Jun 14, 2010 3:51 pm
Posts: 62
Here you go:
http://quackcoder.exofire.net/canvas.html

EDIT: The URL was removed.


Last edited by Quack on Mon Aug 15, 2011 10:18 pm, edited 2 times in total.

Top
 Profile  
 
PostPosted: Mon Aug 15, 2011 2:05 pm 
Harmlessness does no harm
User avatar

Joined: Tue Sep 14, 2004 8:37 pm
Posts: 3810
Location: Ferriday, LA, US
I don't see any problems with the code you've provided -- it doesn't seem to be causing any sort of memory leak (in Firefox 4).

Just to make sure -- do you mean that every 10fps, the memory usage increases by 4kb? Does the total memory usage stay the same, or does it continue to increase? Also, what Web browser are you running this in that gives you this problem?

_________________
What most people don't understand about "enlightenment" is that it is not an end-goal; but where you find yourself just before taking a new "first step."


Top
 Profile  
 
PostPosted: Mon Aug 15, 2011 3:10 pm 
Shake'n'Baker
User avatar

Joined: Mon Jun 14, 2010 3:51 pm
Posts: 62
I am using chrome

It keeps on allocating 4kb every second or so.

Could you tell me how to check this in Firefox?


Top
 Profile  
 
PostPosted: Mon Aug 15, 2011 3:15 pm 
Harmlessness does no harm
User avatar

Joined: Tue Sep 14, 2004 8:37 pm
Posts: 3810
Location: Ferriday, LA, US
Get the Firebug add-on. It will allow you to inspect what's going on with the DOM (including values of variables created by scripts, etc.). Unfortunately, it's only available for Firefox... but you might want to look into similar script-debugging add-ons for Chrome.

I also used Task Manager to keep an eye on the Firefox process's memory usage -- it fluctuated a bit, but it by no means indicated anything out of the ordinary. I'm inclined to think that maybe a bug was introduced in a Chrome update... if so, it will probably be fixed very soon. I don't have access to Chrome, so I cannot test it for myself.

_________________
What most people don't understand about "enlightenment" is that it is not an end-goal; but where you find yourself just before taking a new "first step."


Top
 Profile  
 
PostPosted: Fri Aug 19, 2011 9:44 am 
Shake'n'Baker
User avatar

Joined: Mon Jun 14, 2010 3:51 pm
Posts: 62
Well even if Firefox is immune, chrome and opera aren't!
This memory leak is killing me.

I located the root of my problem, the methods which draws and clears the canvas are the rotten ones!

Drawing method sets pixel data so it should allocate some memory but the method that clears the canvas also allocates memory!! Even simple version of these methods allocate memory.

What to do?

EDIT: The problem was the loop. See here


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group