Hi all,
I have a simple struct that extends ReferenceCountedObject:
struct Thing : public ReferenceCountedObject
{
};
Which I’m using as follows:
int main (int argc, char** argv)
{
ReferenceCountedArray<Thing, CriticalSection> things;
things.add(new Thing());
Thing* thing = things[0].get(); // grab a pointer to thing
std::cout << thing->getReferenceCount() << " refs\n";
things.remove(0);
std::cout << thing->getReferenceCount() << " refs\n"; // (1)
return 0;
}
The docs on ReferenceCountedArray::remove()
say:
The object that is removed will have its reference count decreased, and may be deleted if not referenced from elsewhere.
I might be completely wrong here (bear with me), but In my code at (1) the object is no longer referenced from elsewhere. Am I calling getReferenceCount()
on an object that has been just removed? How come it doesn’t crash?