Atem SDK Disconnect

Ask software engineering and SDK questions for developers working on Mac OS X, Windows or Linux.
  • Author
  • Message
Offline

Mike Ambrose

  • Posts: 189
  • Joined: Wed Jan 13, 2016 11:31 pm

Atem SDK Disconnect

PostMon Apr 25, 2022 5:44 am

What's the best way to manually cleanup an instance of `IBMDSwitcher` in C#?

Also, am I correct in seeing that there is no disconnect method for manually triggering the built-in disconnect event?
Offline

Cameron Nichols

Blackmagic Design

  • Posts: 442
  • Joined: Mon Sep 04, 2017 4:05 am

Re: Atem SDK Disconnect

PostFri May 06, 2022 6:20 am

Hi Mike,

Remove reference to your IBMDSwitcher and related interfaces by assigning to null in C#, or call IUnknown::Release() in C++. Also remove any registered callbacks, so to release references in owner interface objects.

The disconnect will often be as result of action within your application. To handle disconnect due to external event (for instance, switcher is disconnected from network), you should implement IBMDSwitcherCallback callback interface, and within IBMDSwitcherCallback::Notify filter for event type bmdSwitcherEventTypeDisconnected.[1][2]. Register the callback by calling IBMDSwitcher::AddCallback[3].

Regards
Cameron

References (Switchers SDK Manual):
[1] 2.3.3.1 IBMDSwitcherCallback::Notify method
[2] 2.2.2 Switcher Event Type
[3] 2.3.2.31 IBMDSwitcher::AddCallback method
Offline

Mike Ambrose

  • Posts: 189
  • Joined: Wed Jan 13, 2016 11:31 pm

Re: Atem SDK Disconnect

PostFri May 06, 2022 7:42 am

I saw that the library uses its own internal ref count for releasing objects but couldn't ever get memory to go back down (C#). I eventually made a separate program and did the bare minimum (no callbacks, etc) to see if I was missing anything but there was still a memory leak as I created and destroyed instances.

At this point I've just accepted the ~160kb leak as I don't expect users to connect and disconnect multiple times once the program is open.
Offline

Cameron Nichols

Blackmagic Design

  • Posts: 442
  • Joined: Mon Sep 04, 2017 4:05 am

Re: Atem SDK Disconnect

PostThu May 12, 2022 10:32 pm

Hi Mike,

It is probably not such much that there is a leak, but that the garbage collection has not yet occurred.

If you require immediate release of the object, then you can call Marshal.ReleaseComObject to explicitly release the COM object. However please be aware of the dangers in using this and ensure no other part of code is still requiring the IBMDSwitcher, so you may need to further wrap this with IDisposable.

Otherwise you can infer the garbage collection by calling GC.Collect explicitly (there may be performance hit), or better yet call GC.AddMemoryPressure with the approximate size of memory impact to provide guidance to GC to periodically call.

Regards
Cameron

Return to Software Developers

Who is online

Users browsing this forum: No registered users and 19 guests