Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7025125
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:55:59+00:00 2026-05-27T23:55:59+00:00

I am creating a game in javascript and my gameloop is called every 30ms,

  • 0

I am creating a game in javascript and my gameloop is called every 30ms, it leaks a lot of memory as task manager shows the firefox memory usage to increase by 400mb in about 20 seconds.
I am not familiar with how to make sure memory is collected in javascript.

function GameLoop(tick) {
  move(player1.ship);
}

function Player(name) {
  this.id = 0;
  this.name = name;
  this.ship = Ship(this);
}

function Ship(player) {
  this.pos = [1024/2, 768/2];
  this.vel = [0, 0];
  this.angle = 0;
  this.acc = 0;
  this.thrust = 0;
  this.west = 0;
  this.east = 0;
  this.turnRate = 5;
  this.player = player;
  this.size = [40, 40];
  this.ship = canvas.rect(this.pos[0], this.pos[1], this.size[0], this.size[1]);
  this.ship.attr("fill", "red");

  return this;
}

function move(ship) {
  var angle = ship.angle;
  var max_speed = 20;
  var acc_speed = 300;

  var acc = 0;
  if (ship.thrust) {
    acc = 0.25 * acc_speed;
  }
  else { //slow down
    if ((acc - (0.25 * acc_speed)) > 0) {
      acc -= 0.25 * acc_speed;
    }

    else {
      acc = 0;
    }
  }

  var speedx = ship.vel[0] + acc * Math.sin(angle);
  var speedy = ship.vel[1] - acc * Math.cos(angle);
  var speed = Math.sqrt(Math.pow(speedx,2) + Math.pow(speedy,2));

  var speedx = ship.vel[0] + acc;
  var speedy = ship.vel[1] - acc;
  var speed = speedx + speedy;

  if (speed > max_speed) {
    speedx = speedx / speed * max_speed;
    speedy = speedy / speed * max_speed;
  }
  ship.vel = [speedx, speedy];
  ship.pos = [ship.pos[0] + speedx * 0.25, ship.pos[1] + speedy * 0.25];
  ship.ship.attr({x: ship.pos[0], y: ship.pos[1]});
  ship.ship.rotate(angle);
  ship.angle = 0;

  delete this.thrust;
  delete this.west;
  delete this.east;
  delete old_angle;
  delete angle;
  delete max_speed;
  delete acc_speed;
  delete acc;
  delete speedx;
  delete speedy;
  delete speed;

  return this;
}

var player1 = new Player("Player 1");
setInterval(GameLoop, 30);

Ok I commented out some code and have found the offending line, its

ship.ship.rotate(angle);
After commenting that line out javascript is using 4500K.
any idea why this is causing the problem, and how can I still rotate my object without this bit of code?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T23:56:00+00:00Added an answer on May 27, 2026 at 11:56 pm

    The documentation of rotate in RaphaelJS says the following:

    Adds rotation by given angle around given point to the list of transformations of the element.

    That certainly sounds like a potential culprit. The critical words there are add and list.

    What does the transform function show you when you rotate an element twice? My suspicion is that calls to rotate accumulate larger and larger transformation strings. if that’s what’s happening, you can reset the transform,

    el.transform("");
    

    and that should clear the problem you’re seeing.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm creating a game where a lot of images are being used in Actionscript
I'm creating a building game in JavaScript and PHP that involves a grid. Each
I'm creating a simple 2D game in javascript/canvas. I need to figure out the
I'm creating a game for the iPad using Phonegap, which means I'm using JavaScript/
i'm looking at creating a web game using html5 canvas and javascript. i was
I'm creating a simple JavaScript multiple choice game. Here is a sample question: p
I am creating a pacman game in javascript to learn the language, and the
I'm creating a tower-defense game in javascript and want to have a high score
I'm creating a JavaScript game, previously I've always created the whole game inside a
I'm working on creating a javascript game for my own education. The game requires

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.