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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:55:47+00:00 2026-05-28T04:55:47+00:00

I have a plugin with the following structure: (function($) { $.fn.drawFieldsTable = function(options) {

  • 0

I have a plugin with the following structure:

(function($) {
    $.fn.drawFieldsTable = function(options) {
        var settings = {
                url        : 'ajax/pathToFile.php'
        };

        if (options) {
            settings = $.extend(settings, options);
        }

        return this.each(function() {
            $this = $(this);
            $.ajax({
                url  : settings.url,
                type : 'GET',
                data: // some request data here
                success: function(result) {
                    drawFieldElements(result, $this);
                }
            });

            function drawFieldElements(fields, container)
            {
                var replacement = container.clone()
                                           .empty();
                $.each(fields, function(i) {
                    var field;
                    field = buildFieldItem(i, this);
                    replacement.append(field);
                });

                container.replaceWith(replacement);
            }

            function buildFieldItem(i, fieldDataObj)
            {
                var $field = $('<div></div>')
                        .addClass('field')
                        .attr('data-fieldname', i)
                        .attr('data-ord', fieldDataObj.ord);
                return $field;
            }
        });

    };

})(jQuery);

I experience a major memory leak on every buildFieldItem call. If I do not call this function or make it an empty function or just do not use its parameters in its scope – there is no leak. The leak only happens in Internet Explorer (8). In other browsers it’s all ok. Requesting assistance. Thanks in advance.

UPDATE

I’ve updated my question for better demonstrating what buildFieldItem actually does.
As soon as fieldDataObj may contain about 100 items, having these 4 lines solely causes a fountain, not a leak in IE.

UPDATE 2

I’ve replaced clone() and empty() with creating a new div and I also minified buildFieldItem to look like:

function buildFieldItem(i, fieldDataObj)
{
    var $field = $('<div></div>')
            .addClass('field');
    return $field;
}

Still leaking. The only pattern that doesn’t leak is:

function buildFieldItem(i, fieldDataObj)
{
    var $field;
    return $field;
}

Looks like a complete nonsense. The less code in function – the smaller is an overall leak. Could it be that IE can’t delete a reference to the whole function or smth like that?

  • 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-28T04:55:47+00:00Added an answer on May 28, 2026 at 4:55 am

    So, I’ve finally found some time to go back to this old question and finalize. I’ve solved the problem quite quickly, but I’ve just been busy.

    The following lines were causing memory leaks in IE:

    var $isObligatory = $('<input>')
        .attr('type', 'checkbox')
        .attr('name', 'is-obligatory')
        .prop('checked', isObligatory)
        .change(function() {
            settings.gFields.applied[settings.subsection][i].obligate =
                ($(this).prop('checked')) ? 1 : 0;
        });
    

    As you can see, it creates some kind of circular reference when adding a handler for the change event. The reference IE is not smart enough to break.

    The fact is, commenting this out was my first try, but as soon as I’ve also had draggable functionality implemented in the same file, the leak remained, as draggables were causing it too! That’s why I was struggling with that. Moving draggables outside the plugin code solved it.

    Thanks everybody for posting comments and answers. I am sorry for not posting the full code, I thought I was smart enough to post only problematic lines. Sorry for late answer too.

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

Sidebar

Related Questions

I have the following home-grown jquery plugin: (function($) { $.fn.defaultButton = function(button) { var
I have written a small jQuery plugin with the following structure: (function($) { //
Ok, I have the following structure. Basically a plugin architecture // assembly 1 -
Say I have the following file structure: app/ app.py controllers/ __init__.py project.py plugin.py If
I have the following PHP code to display the file structure of my site.
I am using jQuery validation plugin ( http://bassistance.de/jquery-plugins/jquery-plugin-validation/ ) I have following structure: <select
I have the following in my .vimrc syntax on filetype plugin indent on #
I have the following setup: eclipse a standard Java project (A) an eclipse plugin
I have a following problems with eclipse, when I installed ClearCase plugin from this
How do you rotate an image using jQuery-rotate plugin? I have tried the following

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.