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 126075
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T05:15:36+00:00 2026-05-11T05:15:36+00:00

Let me just preface by saying it’s actually my crappy code that’s leaking and

  • 0

Let me just preface by saying it’s actually my crappy code that’s leaking and crashing my browser, I just thought I better make the languages being used as clear as I could from the outset.

I have a test page here and the javascript can be found here. My problem is that when I try and drag and drop either one of the red pieces more than a few times it sucks up all browser resources and crashes the browser. I’m fairly certain the culprit is something in the following function in the Tracker() object but I’m absolutely stuck on how to debug this.

My current most likely culprit:

  function register_draggable(ob) {       ob.config.jqId.draggable({cursor: 'move',                               grid:[ob.config.size, ob.config.size],                               containment: '#chessboard',                               revert: 'invalid',                               start: function() {                                 check_allowable_moves(ob.config.jqLocation,                                                       ob.config.jqId,                                                       ob);                               },                               stop: function() {                                 remove_allowable_moves();                               }                             });   } 

If anyone could take a quick look and give me any suggestions on what I should be looking for, it would be enormously appreciated.

Solution Turns out register_draggable() was the culprit. I registered a new draggable every time the location of a piece updated and all those draggables on the same object were doing nasty things. Currently I now explicity destroy the old draggable before creating a new one. Current code is

    function register_draggable(ob) {     ob.config.jqId.draggable('destroy');     ob.config.jqId.draggable({cursor: 'move',                               grid:[ob.config.size, ob.config.size],                               containment: '#chessboard',                               revert: 'invalid',                               start: function() {                                 check_allowable_moves(ob.config.jqLocation,                                                        ob.config.jqId,                                                        ob);                               },                               stop: function() {                                 remove_allowable_moves();                               }                             });   } 
  • 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. 2026-05-11T05:15:37+00:00Added an answer on May 11, 2026 at 5:15 am

    I don’t think this is actually your problem, but it seems like your making an extra method call on register and check_ allowable_moves

    return {         register_map: function(ob) { map = ob; },         register_piece: function(ob) {           ob.config.tracker = this;           register_draggable(ob);         },         register_draggable: function(ob) { register_draggable(ob); },         check_allowable_moves: function(location, jqPiece, ob) { check_allowable_moves(location, jqPiece, ob); }       } 

    can be shortened to

    return {         register_map: function(ob) { map = ob; },         register_piece: function(ob) {           ob.config.tracker = this;           register_draggable(ob);         },         register_draggable: register_draggable,         check_allowable_moves: check_allowable_moves       } 

    Also

    you are doing a double lookup here:

    function remove_allowable_moves() {         $('.allowable').droppable('destroy');         $('.allowable').removeClass('allowable');       } 

    should be

    function remove_allowable_moves() {         $('.allowable').droppable('destroy')           .removeClass('allowable');       } 

    Also

    Whats the purpose of parsing and int into a float? Take off the parseFloat.

    var x = parseInt(locs[1]); var y = parseInt(locs[2]); var x_min = parseFloat(x)-2; var y_min = parseFloat(y)-2; 

    Finally

    Why are you re-registering as draggable on drop? This could be the culprit, if your registering the draggable multiple times and only destroying it once.

    jqCell.droppable({ accept: '#'+jqPiece.attr('id'),                   drop: function(ev, ui) {                     ob.config.jqLocation = $(this);                     register_draggable(ob);  // why this?                   }                 }); 

    Other thoughts

    Another thing I don’t know if its going to help your performance, but it could clean up your code. the jquery selector allows commas so instead of

    $('#coord-1-1').doStuff(); $('#coord-1-2').doStuff(); $('#coord-1-3').doStuff(); 

    you could do

    $('#coord-1-1, #coord-1-2, #coord-1-3').doStuff(); 

    so your loop would only be concerned with generating the selector string and then you could run you operation on the entire set.

    IMO a cleaner init

    instead of

    var map = new Map('content'); var piece1 = new Piece(map); var piece2 = new Piece(map); var tracker = new Tracker; tracker.register_map(map); map.render(); piece1.render('coord-4-4', '1'); piece2.render('coord-1-1', '2'); tracker.register_piece(piece1); tracker.register_piece(piece2); 

    I’d like to see

    $(document).ready(function() {     $('#content').MapGame({         pieces : { '1' : 'coord-4-4', '2' : 'coord-1-1' }     }); }); 

    Now implementing that is a strech from what you have now, but when building a component for jQuery I like to start with a simple init and work from their. Thats one of the big goals of jQuery is to hide all the junk from the user and just let them spin up and instance of your plugin easily.

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

Sidebar

Related Questions

Let me preface this by saying that I know the ContactCenter sample is just
Preface Let me start off by saying that I'm a relatively new programmer and
Let me preface my question by saying that I am completely unqualified to be
(PHP/MySQL) Let me preface by saying that this works, and that I'm wondering if
Let me preface this by saying I'm a total rails noob. I've just written
Let me just preface this with the fact that I'm pretty green to C#.
Ok, let me preface this by saying that I've read the following: Stackoverflow:how can
Let me preface this question by saying that I am a .NET developer at
Let me preface this by saying that I am relatively new to git so
Let me preface this question by saying that I am relatively new to writing

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.