Frequently Asked Question

How to correctly perform library exiting?
Last Updated a year ago

During its operation, our library allocates certain resources that must be freed before the library is unloaded from the process:

  • Memory buffers:

When you use KYFG_StreamCreateAndAlloc(), and memory buffers are allocated by our library, they are marked as such (to distinguish with a scenario when buffers were allocated by the user program, announced using KYFG_BufferAnnounce() and thus should also be released by the user program). These buffers are released by our library when the user calls KYFG_StreamDelete(), which should be done by the user's application. If you do not call KYFG_StreamDelete(), it will be internally called by the KYFG_CameraClose(), which also should be done by the user's application. If, for some reason, you also do not call KYFG_CameraClose(), it will be internally called by the KYFG_Close(), which your application must call at some point.

  • Background monitoring thread

THere is a background monitoring thread started by our library when an application calls KYFG_Open() (or KYFG_OpenEx()). This thread is stopped when KYFG_Close() is called. Unloading the library without closing all grabber handles may lead to undefined behaviour (uncaught exceptions, etc.). You application must call KYFG_Close() before unloading the library.

  • Callback thread

This is the thread that is waked up by the DMA interrupts and calls stream callback functions in the application. Since this operation is asynchronous, there is no guarantee that application's stream callback will not be called after other ..Close() calls are performed. You application should make sure that all stream callback invocations are ignored after it has closed all handles described above.

NOTE about DllMain's DLL_PROCESS_DETACH in Windows:

One could expect that when our DLL is unloaded from the process memory, it can automatically release all relevant resources (stop threads, unpin and release memory, etc). Unfortunately, as it is stated in the "DllMain entry point" documentation, "There are significant limits on what you can safely do in a DLL entry point". Our library does implement some cleanup steps in its DllMain function, but it is still responsibility of an application to perform full cleanup before library is unloaded.

Please Wait!

Please wait... it will take a second!