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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:28:39+00:00 2026-06-18T00:28:39+00:00

Recetly I was looking for memory leaks in my javascript code. Ater finding some

  • 0

Recetly I was looking for memory leaks in my javascript code. Ater finding some major leaks I starter to look for minor and found something that could be a potential leak – the “hoverIntent.js” plugin. I would like to ask if this is really a leak or am I a bit too overzealous?

General schema fo the code (full code here http://cherne.net/brian/resources/jquery.hoverIntent.js):

(function($) {
    $.fn.hoverIntent = function(f,g) {

    //...


    var track = function(ev) {
        cX = ev.pageX;
        cY = ev.pageY;
    };

    var compare = function(ev,ob) {
        //... function body
    };


    var delay = function(ev,ob) {
       //... function body
    };


    var handleHover = function(e) {
      //... function body
    };


    return this.bind('mouseenter',handleHover).bind('mouseleave',handleHover);
    };
})(jQuery);

I know that many js plugins are written that way, but… If I get that correctly every time I invoke hoverIntent on my object, 3 new functuions (closures) are created? Isn’t it a possible memory leak (or at least a performace issue)?

Wouldn’t it be better to write is this way:

(function($) {

  //create the methods only once on module init?

    var track = function(ev) {
        cX = ev.pageX;
        cY = ev.pageY;
    };

    var compare = function(ev,ob) {
        //... function body
    };


    var delay = function(ev,ob) {
       //... function body
    };


    var handleHover = function(e) {
      //... function body
    };


    $.fn.hoverIntent = function(f,g) {
            //no closures here
    return this.bind('mouseenter',handleHover).bind('mouseleave',handleHover);

    };
})(jQuery);
  • 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-06-18T00:28:40+00:00Added an answer on June 18, 2026 at 12:28 am

    You are correct, your second example would use less memory because of less closure functions. But as soon as you event isn’t callable (element removed etc.) they would disappear again so it is not a “leak” as the memory isn’t lost forever.

    Also many plugins use the closure by setting the current state of an element in a variable instead of the element itself.

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

Sidebar

Related Questions

I found this in some production login code I was looking at recently... HttpContext.Current.Trace.Write(query
I recently was looking at some code that uses SetLength to allocate memory for
Recently I was looking at some source code provided by community leaders in their
Recently I have been refactoring some of my C# code and I found a
I was recently looking at some vp8 sample decoder code when I came upon
I was recently looking through some open source code PicketLink code. If you take
I've recently been looking at functional programming with Javascript, to which I'm a noob.
I've been looking into memory management a lot recently and have been looking at
As some may be aware, I recently posted about high memory usage on my
I recently started looking at MD5 hashing (in Java) and while I've found algorithms

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.