Hi,
I try to to read a file from Swift using class FileHandle and function
This works fine in principle. However, I'm faced with a memory leak. The data allocated in the returned Data buffer is not freed. Is this possibly a bug in the underlying Swift wrapper?
Here is my test function, which reads a file block by block (and otherwise does nothing with the data).
If I call the function in a loop, and watch the program's memory consumption, it's obvious that the memory goes up in each loop by the size of the read file.
Can anybody confirm this behavior or knows how to fix it or if there's possibly already a bug issue opened at Apple?
My environment:
Michael
I try to to read a file from Swift using class FileHandle and function
Code Block Swift @available(macOS 10.15.4, iOS 13.4, watchOS 6.2, tvOS 13.4, *) public func read(upToCount count: Int) throws -> Data?
This works fine in principle. However, I'm faced with a memory leak. The data allocated in the returned Data buffer is not freed. Is this possibly a bug in the underlying Swift wrapper?
Here is my test function, which reads a file block by block (and otherwise does nothing with the data).
Code Block Swift func readFullFile(filePath: String) throws { let blockSize = 32 * 1024 guard let file = FileHandle(forReadingAtPath: filePath) else { fatalError("Failed to open file") } while (true) { guard let data = try file.read(upToCount: blockSize) else { break } } }
If I call the function in a loop, and watch the program's memory consumption, it's obvious that the memory goes up in each loop by the size of the read file.
Can anybody confirm this behavior or knows how to fix it or if there's possibly already a bug issue opened at Apple?
My environment:
macOS 11.3.1 Big Sur
XCode 12.5
Michael