Difference between Cvb.SharedImg and Cvb.Image.IMG

Hi Andrea,

SharedImg
The SharedImg is not shared in a shared memory object. It is more an object oriented representation of the original IMG Object. The SharedImg Object and all other CVB Shared .NET Objects are meant to be used as a replacement of the original objects like the IMG Object to be able to use typical .NET syntax like .Dispose instead of calling a ReleaseObject on an IMG object.

I don´t see that the SharedImg is mentioned in the thread What is the best way to copy an image
Be careful to think that you do not need to release the image if a SharedImg is used. It is correct that with a SharedImg the .NET garbage collector releases the object when it is not needed any more. But the garbage collector does not have the information how big the object is and therefore how important it is to release it early enough. For the garbage collector the size of the object is only a pointer. And then the garbage collector might release the memory sometime in the future or never as this seems to be not important.

If you process images and you get a new SharedImg as result you should dispose it at the moment you do not need the image any more. Otherwise the memory can rise and rise continuously even with SharedIMG Objects.

Acquisition and Processing
If you get a positive result (zero) from the G2Wait call you can safely process your image over the m_Camera variable until you call G2Wait the next time. The next call to G2Wait unlocks the buffer with the old image in the video interface driver for further acquisition and locks the new buffer with the new image which is then available over your m_Camera variable.

You should not call ReleaseObject or Dispose on your m_Camera Object during your processing. This object was created with LoadImageFile and represents the driver instance and the current image. The m_Camera Object should be released when you do not need access to your camera any more. For Example when closing your application.

1 Like