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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:16:54+00:00 2026-05-22T12:16:54+00:00

It’s not the first time I am getting the RuntimeError: underlying C/C++ object has

  • 0

It’s not the first time I am getting the RuntimeError: underlying C/C++ object has been deleted. I’ve solved it many times altering my code in a random but intuitive way but now I am facing this again and just don’t understand why it happens…
What I ask for is a generic approach to confront and solve this error.

I will not post code samples here because my project is too complex and I just can’t figure out where’s the bug. And also because I am asking for the universal solution not just for this case.

Why can the ‘underlying C/C++’ objects be deleted?
How to avoid it?
How to test if the underlying object exists?

  • 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-22T12:16:54+00:00Added an answer on May 22, 2026 at 12:16 pm

    You cannot test if the underlying object exists (e.g., if it has been “deleted”). There is some “trickery” you can employ to “kind-of” help with this, but I don’t recommend it. Rather, IMHO, I’d guess your design lacks strong ownership semantics. (That may be necessary depending on the complexity of the problem and your domain, but I’d recommend against it, if it is avoidable.)

    Your problem is ownership semantics. Most especially in C++, as opposed to other languages that employ memory “garbage collection”, you MUST have a design where you have a strong understanding of “who owns what”. Your design should make it “easy and obvious” to know what objects exist, and who “owns” them.

    Generally, this means to centralize the “creation” and “deletion” of objects into a “parent” of some kind, where there is never any question as to, “Whose object is this?” and “What are your objects that you manage?”

    For example, a “Parent” class will allocate member objects that it “needs”, and only that parent deletes those objects. The parent’s destructor ensures those members are deleted, so those objects don’t accidentally get “left around”. Thus, the parent “knows” its member objects, and when the parent is gone, you KNOW the member objects also are gone. If your design is strongly coupled, then the member objects may reference the parent object, but that is the “deep end of the pool” for ownership semantics (and usually not recommended).

    Some designs can be legitimately very complicated. However, in general, ownership semantics should NEVER be complicated: You should ALWAYS know “who owns what”, and thus, you should ALWAYS know “what objects exist”.

    Other designs are possible with garbage collection languages, where objects may be “free agents” and you trust the garbage collector to do the “hard work” of cleaning up objects about which you’ve lost track. (I’m not partial to those designs, but concede them to be sometimes acceptable in those other languages, based on unique problem domains.)

    If your C++ design relies upon such “free agents” objects, you can write your own garbage collector, or own “utility owner” to clean them up. For example, the MyFreeAgent constructor could register itself with the MyGarbageCollector, and the MyFreeAgent destructor would unregister itself from the MyGarbageCollector. Thus, MyFreeAgent instances could be “cleaned up” by the MyGarbageCollector, or the MyFreeAgent could even kill itself with “delete this;“, and you would KNOW that it is gone (because its destructor would unregister itself from the MyGarbageCollector). In this design, a single MyGarbagageCollector would ALWAYS “know” what MyFreeAgent instances exist.

    Such designs are the “deep end of the pool” and should be used with extreme caution, even though they work, because they have the strong potential to massively de-structure your system. (I’ve used them, but you’ve got to be sure the problem honestly warrants such a design.)

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

Sidebar

Related Questions

I want to count how many characters a certain string has in PHP, but
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a jquery bug and I've been looking for hours now, I can't
I've got a string that has curly quotes in it. I'd like to replace
We're building an app, our first using Rails 3, and we're having to build
I'm making a simple page using Google Maps API 3. My first. One marker
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on

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.