It is likely that "this" is valid, but it can happen that a method is called on an object that has already been deleted.
Then the method will often execute nicely but can crash if access to certain members or in a certain way can no longer be done properly.
For example, the following works nicely for me, despite the object having been deleted
#include <iostream>
#include <string>
using namespace std;
class Test
{
public:
Test() : m_int(0) {}
void noMemberAccess()
{
cout << "noMemberAccess called" << endl;
}
void intReadAccess()
{
cout << "intReadAccess called: value=" << m_int << endl;
}
void stringWriteAccess()
{
m_string = "foo";
cout << "stringWriteAccess called:" << m_string << endl;
}
int m_int;
string m_string;
};
int main()
{
Test *t = new Test;
t->noMemberAccess();
t->intReadAccess();
t->stringWriteAccess();
cout << "deleting object" << endl;
delete t;
t->noMemberAccess();
t->intReadAccess();
t->stringWriteAccess();
return 0;
}
#include <iostream>
#include <string>
using namespace std;
class Test
{
public:
Test() : m_int(0) {}
void noMemberAccess()
{
cout << "noMemberAccess called" << endl;
}
void intReadAccess()
{
cout << "intReadAccess called: value=" << m_int << endl;
}
void stringWriteAccess()
{
m_string = "foo";
cout << "stringWriteAccess called:" << m_string << endl;
}
int m_int;
string m_string;
};
int main()
{
Test *t = new Test;
t->noMemberAccess();
t->intReadAccess();
t->stringWriteAccess();
cout << "deleting object" << endl;
delete t;
t->noMemberAccess();
t->intReadAccess();
t->stringWriteAccess();
return 0;
}
To copy to clipboard, switch view to plain text mode
Obvioulsy the memory pointed to by "t" is still OK enough, but that is not in any way guaranteed.
So different systems or different loads on the same system, etc. can lead to different outcomes. It might work nicely but it could crash.
The result is often weird stack traces, like QString::length() appearing to crash, while actually QString::length() was called on a QString member variable of a destroyed object.
Hence it is important to see how deep the stack trace goes into the method you are experiencing a crash with, but also important to verify that the object the call is coming from is still valid,
Cheers,
_
Bookmarks