G
Guest
I have a project that contains a COM object running in the in-process
configuration. The project was developed by VC6.0 with SP 3. The project has
been put into production for long period of time and it worked just fine.
Right now, I want to migrate the project to VC7.1. During the migration, I
find that there is a bug in the COM object: The COM object has wrongly
Release() for two times, which result in the reference counter to COM object
to 0, triggering the COM object to be deleted in VC7.1 code. This bug is
supposed to be the same as in the VC6.0 code. However, I found that, when the
reference counter reaches 0(or even a negative value), the VC6.0 code does
not delete the COM object and this COM object remains in the COM space. I am
wondering:
1. When the reference counter reaches 0, if the VC6.0 code does not delete
the COM object immediately, who and when will perform the deletion of the COM
object?
2. Why the behavior in the VC7.1 has been changed?
Sample code:
CoCreateInstance(CLSID_XXX, NULL, CLSCTX_ALL, IID_XXXX,(void**)ppv1);
CoCreateInstance(CLSID_XXX, NULL, CLSCTX_ALL, IID_XXXX,(void**)ppv2);
ppv2->Release();
ppv2->Release();// In VC7.1, the object of IID_XXXX is deleted immediately;
// In VC6.0, the object of IID_XXXX would not be
deleted
configuration. The project was developed by VC6.0 with SP 3. The project has
been put into production for long period of time and it worked just fine.
Right now, I want to migrate the project to VC7.1. During the migration, I
find that there is a bug in the COM object: The COM object has wrongly
Release() for two times, which result in the reference counter to COM object
to 0, triggering the COM object to be deleted in VC7.1 code. This bug is
supposed to be the same as in the VC6.0 code. However, I found that, when the
reference counter reaches 0(or even a negative value), the VC6.0 code does
not delete the COM object and this COM object remains in the COM space. I am
wondering:
1. When the reference counter reaches 0, if the VC6.0 code does not delete
the COM object immediately, who and when will perform the deletion of the COM
object?
2. Why the behavior in the VC7.1 has been changed?
Sample code:
CoCreateInstance(CLSID_XXX, NULL, CLSCTX_ALL, IID_XXXX,(void**)ppv1);
CoCreateInstance(CLSID_XXX, NULL, CLSCTX_ALL, IID_XXXX,(void**)ppv2);
ppv2->Release();
ppv2->Release();// In VC7.1, the object of IID_XXXX is deleted immediately;
// In VC6.0, the object of IID_XXXX would not be
deleted