# Foreign Callbacks via Raw Pointers

**URL:** <https://forums.swift.org/t/foreign-callbacks-via-raw-pointers/62932>\
**Category:** Using Swift\
**Created:** [February 3, 2023, 12:46pm UTC](https://forums.swift.org/t/foreign-callbacks-via-raw-pointers/62932 "2023-02-03T12:46:36Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![stuchlej](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/stuchlej/32/7751_2.png) [@stuchlej](https://forums.swift.org/u/stuchlej)\
**Post date:** [February 3, 2023, 12:58pm UTC](https://forums.swift.org/t/foreign-callbacks-via-raw-pointers/62932/2 "2023-02-03T12:58:52Z")

</div>

If you're looking for more information, I have [How do closures work (memory management)](https://forums.swift.org/t/how-do-closures-work-memory-management/47512) and maybe this post also lightly touches the topic [Dynamically loading a Swift `shared object` / `dylib`](https://forums.swift.org/t/dynamically-loading-a-swift-shared-object-dylib/62732) .

At the first glance I don't see anything wrong (albeit the callback casting seems a little clumsy to me). The context of those Swift closures never "leaves" the Swift environment - worst case scenario: those closures are never released by the dictionary that retains them.

My only concern would be, that if you're in multi-threaded environment, the access to the `callbacks` dictionary should be done in a safe manner.

---

_[View the full topic](https://forums.swift.org/t/foreign-callbacks-via-raw-pointers/62932)._
