fix: small memory leak when opening the switcher (closes #4255)
This commit is contained in:
1 parent
5b0df6bd4c
commit
0a6485e024
2 files changed
+6
-10
No files matched your search
@@ -193,12 +193,10 @@ extension AXUIElement {
|
||||
|
||||
func unboxAxValue<T>(_ attributeValue: Any, _ axType: AXValueType, as _: T.Type = T.self) -> T? {
|
||||
let axValue = unsafeDowncast(attributeValue as CFTypeRef, to: AXValue.self)
|
||||
let result = UnsafeMutablePointer<T>.allocate(capacity: 1)
|
||||
defer { result.deallocate() }
|
||||
guard AXValueGetValue(axValue, axType, result) else {
|
||||
return nil
|
||||
return withUnsafeTemporaryAllocation(of: T.self, capacity: 1) { buffer in
|
||||
guard AXValueGetValue(axValue, axType, buffer.baseAddress!) else { return nil }
|
||||
return buffer[0]
|
||||
}
|
||||
return result.pointee
|
||||
}
|
||||
|
||||
/// we combine both the normal approach and brute-force to get all possible windows
|
||||
|
||||
@@ -36,12 +36,10 @@ class Applications {
|
||||
static func removeZombieWindows() {
|
||||
let wIds = Windows.list.compactMap { $0.cgWindowId }
|
||||
guard !wIds.isEmpty else { return }
|
||||
let values = UnsafeMutablePointer<UnsafeRawPointer?>.allocate(capacity: wIds.count)
|
||||
for (i, id) in wIds.enumerated() {
|
||||
values[i] = UnsafeRawPointer(bitPattern: UInt(id))
|
||||
let rawIds: CFArray = wIds.map { UnsafeRawPointer(bitPattern: UInt($0)) }.withUnsafeBufferPointer {
|
||||
CFArrayCreate(nil, UnsafeMutablePointer(mutating: $0.baseAddress), $0.count, nil)
|
||||
}
|
||||
let rawIds = CFArrayCreate(kCFAllocatorDefault, values, wIds.count, nil)
|
||||
let descriptions = (CGWindowListCreateDescriptionFromArray(rawIds) as? [[CFString: Any]])
|
||||
let descriptions = CGWindowListCreateDescriptionFromArray(rawIds) as? [[CFString: Any]]
|
||||
let existingWids = descriptions?.compactMap { $0[kCGWindowNumber] } as? [CGWindowID]
|
||||
guard let existingWids else { return }
|
||||
let believedAlive = Set(wIds)
|
||||
|
||||
Reference in new issue
Block a user