[KN / iOS] Question regarding the worker and memor...
# kotlin-native
i
[KN / iOS] Question regarding the worker and memory leaks, I have a small test (not a unit test but rather screen with one button) that reads 500 times 1.2Mb text file into the memory via worker. I see after worker terminated the memory released but not to the previous level (before test started) but +500Kb. Every time I repeat this exercise I see +500Kb increase after every test. I’m not really sure if that Xcode Instruments misrepresents the memory or there is some leaks inside the KN runtime.
Copy code
val worker = Worker.start()
        worker.execute(
            mode = TransferMode.SAFE,
            producer = { { operation() }.freeze() },
            job = {
                it()
            }
        )
        worker.requestTermination()
To read from file
NSString.stringWithContentsOfURL(url = file, encoding = NSUTF8StringEncoding, error = null)
message has been deleted
Not sure that ^^^ will help, but it seems this guy is still alive and it exact 500Kb
again not sure if this makes sense but I see in https://github.com/JetBrains/kotlin-native/blob/master/runtime/src/main/cpp/Worker.cpp
pthread_create
but where thread is shutdown with
pthread_exit
?
b
That looks like a bug to me (missing pthread_exit)?
o
No need for explicit thread exit, as mentioned in the bug. Btw, why do you need to create worker for every file read? You can reuse the same worker.
👍 1
b
Yep issue is updated. Worker implementation seems fine
o
it could be not the real memory, but just process memory map entry, I’d check if there’s underlying RAM there
i
Thanks for the clarification, I will check. Yeah I know that worker can be shared and it should. It's just a test to get some stats how KN runtime is doing, we are experimenting to see if we can use it in our prod project.