Reference Count GenICam.vin CVB 13.01.xxx

Hello,

I remember from earlier versions (starting with10.x/11.x) that for the GenICam.vin the reference count was 2 by default (1 for the handle of the camera and 1 for the GenICam Nodemap). Thus, if you load the GenICam.vin the returned reference count was 2.

Now with CVB 13.01.xxx (x64), the returned reference count is 1.

Is this change of behavior intended?

For my test, I plugged in a Manta camera and ran following program:

static void Main(string[] args)
{
      Cvb.Image.LoadImageFile(Environment.ExpandEnvironmentVariables("%CVB%") + @"\Drivers\GenICam.vin", out Cvb.Image.IMG hImg);
      Console.WriteLine("RefCount = " + Cvb.Image.RefCount(hImg));
      Cvb.Image.ReleaseObj(hImg);
      Console.ReadLine();
}

This is the outcome:
image

We are just wondering as we upgrading some older software and we have an assert statement in our application which checks the reference count against the value 2 after loading the driver. Thus I want to double check if this is the intended behavior for newer versions of CVB?

Thanks.

Hi @Amicelli

an important rule about reference counting is this: Never expect the reference count to have a specific value! Of course the reference count is not generally arbitrary. After loading a driver (or an image or a video or an emu) I can reasonably expect the reference count to have a value > 0. If I call ShareObject on it, I can reasonably expect it to have a value higher than before. If I call ReleaseObject on it I can expect the value to smaller than before. But the actual value (or the offset by which it changes when calling ShareObject or ReleaseObject) is an implementation detail and is subject to change without further notice (which I think is reasonable as well - after all nobody every promised the reference count to have the value x in any given situation).

In summary I’d say that the assertion that after loading the driver has a reference count of exactly 2 was a problematic one (and the assertion that it is exactly 1 would be equally problematic).

For those who are now scratching their heads I have two good news:

  1. Since version 13.00.000 the IsImage function is finally back on track and you can rely on it to give a correct answer without running into undefined behavior. This alone might make a few of the ReferenceCount calls that people have been using obsolete.
  2. What’s even better is that with the new CVB.Net, CVB++ and CVBpy APIs you won’t have to worry about reference counting ever again because the smart pointers (CVB++) or the runtime (CVB.Net, CVBpy) will take care of that detail…
4 Likes