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 leak when using Socket.readString #190

Open
johannes87 opened this issue Jul 14, 2020 · 1 comment
Open

Memory leak when using Socket.readString #190

johannes87 opened this issue Jul 14, 2020 · 1 comment

Comments

@johannes87
Copy link

johannes87 commented Jul 14, 2020

The following code results in a big amount of memory being allocated by the process that is not being released.
After 20k connections, the used memory of the process is more than 100MB. After removing the call to readString, the memory usage does not increase anymore. I tested this with BlueSocket 1.0.52.

var i = 0
while true {
    let socket = try Socket.create()
    try! socket.connect(to: "localhost", port: 31337)
    let serviceResponse = try! socket.readString()!

    i += 1
    print(i, String(describing: serviceResponse))
    Thread.sleep(forTimeInterval: 0.001)
}

The socket connects to a service that first responds with "foobar" and then closes the connection.

The code for reproducing this can be found in the repository https://github.com/johannes87/TestBlueSocketMemoryLeak

The target TestService inside the Xcode project is the "foobar" service mentioned above.

@johannes87
Copy link
Author

I noticed that when I run dispatchMain() after the loop (and changing the while condition to e.g. "i < 20000"), the process uses less memory again. Before the connection loop, the memory usage is about 6MB, and after calling dispatchMain it is about 25MB. The maximum amount of memory used was ~135MB.

johannes87 added a commit to johannes87/Hotspot-Menubar that referenced this issue Sep 28, 2021
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

1 participant