OpenComputers

OpenComputers

49M Downloads

Memory leak in thread API

nightcn1080 opened this issue ยท 0 comments

commented

I suspect to have found a memory leak in the thread API. The problem can be reproduced in OpenOS as follows:

/boot/95_test.lua

local thread = require("thread")
local event = require("event")

function createThread(_, recvOnUUID, recvFromUUID, recvNetID, _, recvData)
  thread.create( function() 
    print("thread end")
  end):detach()
end

event.listen("memory_leak_test", createThread)

/bin/test.lua

local computer = require("computer")

function memoryCheck()
  local total = computer.totalMemory()
  local max = 0
  for _=1,40 do
    max = math.max(max, computer.freeMemory())
    os.sleep(0) -- invokes gc
  end
  io.write(string.format("Total%12d\nUsed%13d\nFree%13d\n", total, total - max, max))
end

while true do
  print("Sending signal...")
  computer.pushSignal("memory_leak_test")
  memoryCheck()
  os.sleep(1)
end

After executing the "test" program, the memory fills up step by step. In "ps" the thread counter increases more and more. But if I add an os.sleep(1) in the "95_test.lua" after the "print("thread end")" this does not happen.