We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using this patch to not retain objects in our internal tables:
diff --git a/Sources/SwiftGodot/Core/Wrapped.swift b/Sources/SwiftGodot/Core/Wrapped.swift index f440503..bbc7cec 100644 --- a/Sources/SwiftGodot/Core/Wrapped.swift +++ b/Sources/SwiftGodot/Core/Wrapped.swift @@ -303,9 +303,9 @@ func bindGodotInstance(instance: some Wrapped, handle: UnsafeRawPointer) { tableLock.withLockVoid { if frameworkType { // Speed optimization, I do not think that we need this - //liveFrameworkObjects [handle] = instance + liveFrameworkObjects [handle] = WeakWrap(wrapped: instance) } else { - liveSubtypedObjects [handle] = instance + liveSubtypedObjects [handle] = WeakWrap(wrapped: instance) } } @@ -383,10 +383,17 @@ public func unregister<T:Wrapped> (type: T.Type) { } } +class WeakWrap { + weak var wrapped: Wrapped? + public init(wrapped: Wrapped) { + self.wrapped = wrapped + } +} + /// Currently contains all instantiated objects, but might want to separate those /// (or find a way of easily telling appart) framework objects from user subtypes -var liveFrameworkObjects: [UnsafeRawPointer:Wrapped] = [:] -var liveSubtypedObjects: [UnsafeRawPointer:Wrapped] = [:] +var liveFrameworkObjects: [UnsafeRawPointer:WeakWrap] = [:] +var liveSubtypedObjects: [UnsafeRawPointer:WeakWrap] = [:] // Lock for accessing the above var tableLock = NIOLock() @@ -407,7 +414,7 @@ fileprivate var bindingObject: UnsafeMutableRawPointer? = nil /// are the only ones that would keep state func lookupLiveObject (handleAddress: UnsafeRawPointer) -> Wrapped? { tableLock.withLock { - return liveSubtypedObjects [handleAddress] + return liveSubtypedObjects [handleAddress]?.wrapped } } @@ -419,14 +426,14 @@ func lookupLiveObject (handleAddress: UnsafeRawPointer) -> Wrapped? { /// we do not get the base type, but the most derived one func lookupFrameworkObject (handleAddress: UnsafeRawPointer) -> Wrapped? { tableLock.withLock { - return liveFrameworkObjects [handleAddress] + liveFrameworkObjects [handleAddress]?.wrapped } } func objectFromHandle (nativeHandle: UnsafeRawPointer) -> Wrapped? { tableLock.withLock { if let o = (liveFrameworkObjects [nativeHandle] ?? liveSubtypedObjects [nativeHandle]) { - return o + return o.wrapped } return nil
The text was updated successfully, but these errors were encountered:
Additional improvements:
https://gist.github.com/migueldeicaza/8c655549f215e1dd5887ee47c37ed803
Sorry, something went wrong.
Another one: https://gist.github.com/migueldeicaza/263d716120391c8b82954378eb841fa8
Another one: https://gist.github.com/migueldeicaza/881b39524fc1c0a93aa83cfe1c5dda52
Another one:
https://gist.github.com/migueldeicaza/82c490995cfe2b949660300277857704
No branches or pull requests
Using this patch to not retain objects in our internal tables:
The text was updated successfully, but these errors were encountered: