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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:18:15+00:00 2026-05-24T12:18:15+00:00

var recurse = function(steps, data, delay) { if(steps == 0) { console.log(data.length) } else

  • 0
var recurse = function(steps, data, delay) {
    if(steps == 0) {
        console.log(data.length)
    } else {
        setTimeout(function(){
            recurse(steps - 1, data, delay);
        }, delay);
    }
};

var myData = "abc";
recurse(8000, myData, 1);

What troubles me with this code is that I’m passing a string on 8000 times. Does this result in any kind of memory problem?

Also, If I run this code with node.js, it prints immediately, which is not what I would expect.

  • 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-24T12:18:15+00:00Added an answer on May 24, 2026 at 12:18 pm

    If you’re worried about the string being copied 8,000 times, don’t be, there’s only one copy of the string; what gets passed around is a reference.

    The bigger question is whether the object created when you call a function (called the “variable binding object” of the “execution context”) is retained, because you’re creating a closure, and which has a reference to the variable object for the context and thus keeps it in memory as long as the closure is still referenced somewhere.

    And the answer is: Yes, but only until the timer fires, because once it does nothing is referencing the closure anymore and so the garbage collector can reclaim them both. So you won’t have 8,000 of them outstanding, just one or two. Of course, when and how the GC runs is up to the implementation.

    Curiously, just earlier today we had another question on a very similar topic; see my answer there as well.

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

Sidebar

Related Questions

var thumbs = document.getElementsByTagName(img); for (var i=0; i<thumbs.length; i++) { Core.addEventListener(thumbs[i], click, function() {alert(i);});
var y = new w(); var x = y.z; y.z= function() { doOneThing(); x();
What am I doing wrong here? How can I execute my action? var recurse
var Box = function(){ this.parm = {name:rajakvk,year:2010}; Box.prototype.jspCall = function() { $.ajax({ type: post,
var carousel = jQuery('#mycarousel').data('jcarousel'); var index = carousel.size() + 1; carousel.size(index); var html =
var selValues = {}; selValues['234'] = $('#asd').val(); selValues['343'] = function () { var el
var array1 = {}; array1['one'] = new Array(); array1['one']['data'] = 'some text'; array1['one']['two'] =
I'm using the following for a dropdown: /* recurse through dropdown menus */ $('.dropdown').each(function()
var a = [1,4,5]; var e = a.length--; Here e variable will contain 5.
var encClinic = new Ext.chart.StackedBarChart({ store: new Ext.data.Store({ reader:encReader, url:data.jsonUrl, baseParams:{ cmd:'OHMjson.Graph', graphName:'ENC', graphType:'Clinics'

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.