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

  • Home
  • SEARCH
  • 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 4112956
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T22:15:42+00:00 2026-05-20T22:15:42+00:00

I have a program that uses Javascript as a scripting language binding to a

  • 0

I have a program that uses Javascript as a scripting language binding to a larger C++ application. I use V8 and webkit interchangeably, but the underlying runtime shouldn’t matter for this question.

In this application, I have dynamically created objects will receive callbacks. I’ll create this callback binding like this…

function f() {
  var obj = CreateNewCallbackObj();
  obj.onCallback = dowork; // dowork is a function
}

Clearly this will have GC problems because obj has gone out of scope and will be deleted eventually.

What I want is for the object to self manage its lifetime. The object will eventually receive a callback that will signal the end of its life, and when that happens it can delete itself.

One thought is to self-reference by adding an obj.myself=obj. This seems like the wrong way to do it, but it might work unless a garbage collection algorithm is smart.

Is there a right way to do this? There is no underlying persistant DOM that is built to store objects in, all of the JS objects are allocated dynamically as needed but need some way to stick around within the JS engine.

  • 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-20T22:15:43+00:00Added an answer on May 20, 2026 at 10:15 pm

    Self-references will not guarantee that anything stays alive. In fact, there’s about no self-respecting implementation of a GC’d language (that I’m aware of) that uses refcounting alone. Don’t even think of abusing the GC algorithm, or any other implementation-defined detail – that way lies madness.

    As for alternatives: Create some always reachable (e.g. global) object which holds all these objects (and thus keeps them alive) and provide a method to remove an object. Then pray nobody else got a reference – or even better, don’t worry about this. The whole point of GC is that you shouldn’t (have to) know/care when memory is released.

    You could also add an alive property, check that at the start of all methods and raise an error if a method is invoked when !this.alive – that’s no guarantee, of course, but it may help debugging.

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

Sidebar

Related Questions

I have a program that uses the mt19937 random number generator from boost::random. I
I have a program that uses JAMA and need to test is a matrix
I have a Python program that uses the threading module. Once every second, my
I have a Windows C# program that uses a C++ dll for data i/o.
I have a java client program that uses mdns with service discovery to find
I have a small command line program that uses the Team System API. When
I have a program that uses curses, and then returns to the main script
I have a C# program that uses a production grammar to generate 3D models
I have a java program that uses a weak hashmap for caching some things,
Question: I have written a console program that uses the SQL server 2005 web

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.