I am learning some COM code and the following code puzzled me.
STDMETHODIMP _(ULONG) ComCar::Release()
{
if(--m_refCount==0)
{
delete this; // how could this "suicide" deletion be possible?
return 0;
}
return m_refCount;
}
Yes. this is the similar code from here. And there I askes about how could a memeber method delete its belonging object. Now I am thinking about these 2 scenarios.
1- If I define a class without making an instance of it. Would any data related to this type exist in runtime?
2- If I only make 1 instance of the class and make the very single object commit suicide via the above code. After the object is deleted, where could the object's methods stay? Or am I paying too much attention to the encapsulation illusion?
I am wondering whether class methods are first name-mangled and then stored in the code/text segment of the program without regard to the existence of any object of its type. So the class methods exist as long as you define them.