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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:21:22+00:00 2026-05-25T11:21:22+00:00

Can somebody explain in detail how Javascript engines deal with circular references ? Is

  • 0

Can somebody explain in detail how Javascript engines deal with circular references ? Is there a big difference between browsers or even node.js ?

What I’m talking about is an explicit back-/next reference within objects. For instance:

var objA = {
    prop: "foo",
    next: null
};

var objB = {
    prop: "foo",
    prev: null
};

objA.next = objB;
objB.prev = objA;

There we go. If we do a console.log( objA ) we can see that we created an infinite chain.
The big question is, is this bad ? Does it create memory leaks when not explicitly cleaned?

So do we have to

objA.next = null;
objB.prev = null;

or will the garbage collectors take care of us on constellations like this?

  • 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-25T11:21:23+00:00Added an answer on May 25, 2026 at 11:21 am

    Any half-decent garbage collector will handle cycles.

    Cycles are only a problem if you do naive reference counting.

    Most garbage collectors don’t do ref-counting (both because it can’t handle cycles, and because it’s inefficient). Instead, they simply follow every reference they can find, starting from “roots” (typically globals and stack-based variables), and mark everything they can find as “reachable”.

    Then they simply reclaim all other memory.

    Cycles are no problem because they just mean that the same node will be reached multiple times. After the first time, the node will be marked as “reachable” already, and so the GC will know that it’s been there already, and skip the node.

    Even more primitive GC’s based on reference-counting typically implement algorithms to detect and break cycles.

    In short, it’s not something you have to worry about.
    I seem to recall that IE6’s Javascript GC actually failed to handle cycles (I could be wrong, it’s been a while since I read it, and it’s been much, much longer since I touched IE6), but in any modern implementation, it is no problem.

    The entire point in a garbage collector is to abstract away memory management. If you have to do this work yourself, your GC is broken.

    See MDN for more information on modern garbage collection and the mark-and-sweep algorithms that are used.

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

Sidebar

Related Questions

Can somebody explain difference between before and after trigger in oracle 10g with an
I'm running a Django app using FastCGI and lighttpd. Can somebody explain me what
Can somebody explain me why is this not working? I'm executing XmlNode xmlNode =
Can somebody explain to me why the following works: template<class T> class MyTemplateClass {
Can somebody explain why the following code is not valid? Is it because the
Can somebody explain why the .Net framework team decided that a delegate without subscribers
Can somebody explain this entry in web.xml ? When it has to be used
Can somebody explain me why this T-SQL code only returns one row with the
Can somebody explain why it is so ?
Can somebody explain what is the exact reason behind using Action<T> and Predicate<T> as

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.