Basic COM  «Prev  Next»

Reference Counting - Exercise

Reference Counting

Objective: Debug the following client-side pseudo-code.

Instructions

There is a problem with the following piece of code.
  1. Identify the problem.
  2. Describe a solution to the problem.

HRESULT hr;
IMyComInterface *piy_1, *piy_2;

piy_1 = get an interface pointer to IMyComInterface;
piy_2 = piy_1;

…

piy_1->Release();
piy_2->Release();

Exercise scoring

This exercise is worth a total of 10 points. There are two possible solutions. You must get one of them to receive any credit.

Exercise submission

Write or paste your answer in the text area below. When you are done, click the Submitbutton to submit your answer.