qaisjp

Test for mtasa-blue 5a62615031ab634de9ebae5ceb11afc661ad3525

Feb 24th, 2016
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.36 KB | None | 0 0
  1. -- Test for https://github.com/multitheftauto/mtasa-blue/commit/5a62615031ab634de9ebae5ceb11afc661ad3525
  2. -- You can place this script in a "client.lua" file and set it as shared.
  3.  
  4. server = not triggerServerEvent
  5. filename = server and "client.lua" or "testfile2.txt"
  6.  
  7. if not server then
  8.     addEventHandler("onClientResourceStart", resourceRoot, function()
  9.         if not File.exists("testfile2.txt") then
  10.             File.new("testfile2.txt"):close()
  11.         end
  12.     end)
  13. end
  14.  
  15. addCommandHandler("test" .. (server and "server" or "client"), function()
  16.     outputDebugString("start test 1")
  17.     file = File(filename)
  18.     file:close()
  19.     file = nil
  20.     outputDebugString("dereferenced closed file. collecting garbage...")
  21.     collectgarbage()
  22.     outputDebugString("finish test 1")
  23.  
  24.     outputDebugString("start test 2")
  25.     file = File(filename)
  26.     file = nil
  27.     outputDebugString("dereferenced open file. collecting garbage...")
  28.     collectgarbage()
  29.     outputDebugString("finish test 2")
  30.  
  31.     outputDebugString("start test 3")
  32.     file = File(filename)
  33.     file = nil
  34.     outputDebugString("dereferenced open file. NOT collecting garbage... use /trygarbage. use /forcecollect to clean up.")
  35. end)
  36.  
  37. addCommandHandler("trygarbage", function()
  38.     local f
  39.     for i=1, 13337 do
  40.         f = function()
  41.             f = function()
  42.                 return i
  43.             end
  44.         end
  45.  
  46.         f = f()
  47.     end
  48. end)
  49. addCommandHandler("forcecollect", function() collectgarbage() end)
Advertisement
Add Comment
Please, Sign In to add comment