Skip to content
New issue

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

Memory leaks occured when obtain some value related to URLResourceKey #1087

Open
baju0218 opened this issue Dec 12, 2024 · 2 comments
Open

Comments

@baju0218
Copy link

baju0218 commented Dec 12, 2024

When I try to obtain free disk space size through the example code in the document below, but it seems that memory leak occurs when using all api related to URLResourceKey. Running with instrument, it seems that objects such as CFString are not released inside Foundation.

https://developer.apple.com/documentation/foundation/urlresourcekey/checking_volume_storage_capacity

example)

while (true) {
  let fileURL = URL(fileURLWithPath:"/")
  do {
      let values = try fileURL.resourceValues(forKeys: [.volumeAvailableCapacityForImportantUsageKey])
      if let capacity = values.volumeAvailableCapacityForImportantUsage {
          print("Available capacity for important usage: \(capacity)")
      } else {
          print("Capacity is unavailable")
      }
  } catch {
      print("Error retrieving capacity: \(error.localizedDescription)")
  }
}
@jrflat
Copy link
Contributor

jrflat commented Dec 17, 2024

Wrapping the do/catch in an autoreleasepool prevents the memory leak, but we should fix this internally. I'll forward this to the responsible team, thanks for filing!

@baju0218
Copy link
Author

baju0218 commented Dec 18, 2024

Actually, I want to use above code in objective-c side. In swift, it's possible to prevent memory leakage by wrapping with autoreleasepool, but objective-c can't prevent it with the @autoreleasepool.
스크린샷 2024-12-18 오후 4 18 31

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants