QueryInterface Regarding....
-
Hi, My Program is supposed to run contineously so i need to concern about memory management with COM. Here is the scenario, I created a COM Object using CreateInstance() using that COM object i am creating another object using QueryInterface. Here is my question. 1. if i am releasing the first object which i got using CreateInstance, then subsequently the objects which are created using that will be removed from memory right? Since if i call release for object got using QI causing crash. But i am fine if i release the first object, but i am afraid this would lead to a memory leak issue. :( Kindly Advice! Thanks in advance:rose: -Ganesha
Thanks a lot
-
Hi, My Program is supposed to run contineously so i need to concern about memory management with COM. Here is the scenario, I created a COM Object using CreateInstance() using that COM object i am creating another object using QueryInterface. Here is my question. 1. if i am releasing the first object which i got using CreateInstance, then subsequently the objects which are created using that will be removed from memory right? Since if i call release for object got using QI causing crash. But i am fine if i release the first object, but i am afraid this would lead to a memory leak issue. :( Kindly Advice! Thanks in advance:rose: -Ganesha
Thanks a lot
Unless the second object is aggregated in the COM sense, i.e. it's a server that lives inside another server, thou-shall-not-create-objects-with-QueryInterface! QueryInterface has a well-defined purpose and functionality: you ask a COM object you already have an interface to for another interface, the object returns that interface if it implements it and fails with
E_NOINTERFACE
if it does not implement the requested interface. If such functionality is desired you should create an interface function that clearly says it will create another COM object.ganesa moorthy wrote:
if i am releasing the first object which i got using CreateInstance, then subsequently the objects which are created using that will be removed from memory right?
Not if the object still has clients, i.e. it's reference count has not reached zero. It looks to me as you two objects are too tightly connected. If you make them available in the same server (COM object) but perhaps reachable from different interfaces, you can use
QueryInterface
correctly. Another alternative is to make the two objects less connected and actually have two different COM objects."It's supposed to be hard, otherwise anybody could do it!" - selfquote
"High speed never compensates for wrong direction!" - unknown