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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T01:37:57+00:00 2026-05-18T01:37:57+00:00

My program is crashing and I’m having a hard time wrapping my head around

  • 0

My program is crashing and I’m having a hard time wrapping my head around why it crashes. The main problem is that the wxwidgets documentation says that reference counting is used for wxImage objects. What exactly does this mean? Why does this code crash it?

wxImage* t = m_default_image; //m_default_image is a pointer pointing to a valid wxImage object.

wxDELETE(m_default_image);
if(t->IsOk())
{
    wxLogMessage("reference counting works!");
}

The line that crashes is the t->IsOK(). Shouldn’t the reference counting prevent the actual object from being deleted so my t ptr still points to something valid?

  • 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-18T01:37:58+00:00Added an answer on May 18, 2026 at 1:37 am

    Let me explain what is happening:

    1. You create a pointer to a wxImage that you have already created somewhere.
    2. You then delete it.
    3. You then attempt to dereference a deleted pointer and call ‘IsOk()’ on the resulting object, which doesn’t exist anymore, because of the previous step.

    Step 2 may or may not have actually deleted the object, but it likely deleted the reference as well. Depending on how wx implemented reference counting, and how you’ve managed references, the wxImage object may have a reference count of one at the start of your routine – therefore, wxDELETE will reduce the reference count to zero, and thus delete the object as well.

    There is no way that wx could automatically manage your objects using reference counts if you are using pointers in the way you are. Perhaps you want to use the copy constructor, and stop using manual memory handling? C++ has the RAII technique – use it.

    Lastly, can I ask why m_default_image is a pointer? You’re just making life hard for yourself by using raw pointers all the time.

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

Sidebar

Related Questions

I'm having trouble with my program crashing. I get that Program.exe has stopped working
I noticed that my program was crashing because it was running out of memory.
My program is crashing every time I try to store a COM pointer into
Is there is easy command in MATLAB which prevents program from crashing when it
How can I prevent the following code crashing my program? ::MessageBox(NULL, Lbefore, NULL, MB_OK);
My program is like this ( main.c ): #include <stdlib.h> #include <stdio.h> void main(){
My program keeps crashing when I close the frame. I've narrowed the cause down
The following program keeps crashing and I can't figure out what's wrong. It seems
In one RTOS, i'm debugging one issue which is, program is crashing one point
My program is crashing at the end of execution, and couldnt even see stack

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.