C function pointers are imported into Swift as closures

https://stackoverflow.com/questions/24330263/lifetime-of-retained-memory-in-swift-closures
https://developer.apple.com/library/content/documentation/Swift/Conceptual/BuildingCocoaApps/InteractingWithCAPIs.html#//apple_ref/doc/uid/TP40014216-CH8-XID_13

One generally does not need to worry about how __block variables work internally.

But basically, the variable is wrapped in a simplified “object” kind of thing, with the actual “variable” being a field of this “object”, which is memory-managed through reference counting.

Blocks that capture them hold “strong references” to this pseudo-object thing — when a block is created on the heap (technically, when they are copied from stack blocks to the heap) that uses this __block variable, it increases the reference count; when a block that uses it is deallocated, it decreases the reference count. When the reference count goes to 0, this pseudo-“object” is deallocated, invoking the appropriate destructor for its variable type first.