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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T10:18:35+00:00 2026-05-30T10:18:35+00:00

Reading this stackoverflow answer : QWeakPointer – Do you sense a reoccurring pattern? Just

  • 0

Reading this stackoverflow answer :

QWeakPointer – Do you sense a reoccurring pattern? Just as
std::weak_ptr and boost::weak_ptr this is used in conjunction with
QSharedPointer when you need references between two smart pointers
that would otherwise cause your objects to never be deleted.

My question is – could anybody explain me such situation on a simple example, when two referencing smart pointers could cause non-deleted objects?

Thank you in advance..

  • 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-30T10:18:36+00:00Added an answer on May 30, 2026 at 10:18 am

    In the following example, neither of the S objects will ever be destroyed, because the object pointed to by a owns the object pointed to by b, and vice-versa.

    struct S {
        std::shared_ptr<S> p;
    };
    
    void f()
    {
        std::shared_ptr<S> a(new S());
        std::shared_ptr<S> b(new S());
        a->p = b;
        b->p = a;
    }
    

    std::weak_ptr is used to break reference cycles. If object lifetime is known to extend beyond the lifetime of the non-owning pointer, raw pointers can be used as well.

    The same principles apply to Qt’s smart pointers, like QWeakPointer.

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

Sidebar

Related Questions

I'm asking this question after reading this answer on StackOverflow. The supplied answer works
I was reading this thread/post: https://stackoverflow.com/questions/262298/windows-c-ui-technology and am also wondering about a non .NET
After reading this answer: best way to pick a random subset from a collection?
In this stackoverflow answer a commenter mentioned that private nested classes can be quite
I've been searching all over StackOverflow but i couldn't find an answer for this.
I was reading this StackOverflow question about eager loading which led me to this
I know from reading this Stackoverflow question that the complier will look at your
This is my first time posting on Stackoverflow, but I've been reading through many
I have been reading stackOverflow answers for this question for hours. Please help me.
While reading a post on StackOverflow (http://stackoverflow.com/questions/1502081/im-trying-to-optimize-this-c-code-using-4-way-loop-unrolling), which is now marked as closed, I

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.