lua-users home
lua-l archive

GC stops working after collecting a chunk of memory

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


```lua
collectgarbage('generational', 10, 50)

debug.sethook(function()end, 'c')

print(_VERSION)
print(collectgarbage('count'))

localt= {}
fori=1, 100000do
t[i] = (''):rep(5000) ..tostring(i)
end

print(collectgarbage('count'))

t=nil

collectgarbage()
collectgarbage()

print(collectgarbage('count'))

localt= {}
fori=1, 1000do
t[i] = (''):rep(100000) ..tostring(i)
t[i] =nil
ifi%100==0then
print(collectgarbage('count'))
end
end
```

Run this code, prints:

```
Lua 5.4
22.7333984375
595727.66894531
84.794921875
19628.545898438
39172.432617188
58716.319335938
78260.206054688
97804.092773438
117347.97949219
136891.86621094
156435.75292969
175979.63964844
195523.52832031
```

Seems GC stops working.

But if I set parametersfor `collectgarbage` to default (`20, 100`, makes it more negative), it works fine.

This line `debug.sethook(function()end,'c')` is not necessary. If you remove this line, you need to set the GC parameters to `10, 20` to reproduce this problem.

-- sumneko

AltStyle によって変換されたページ (->オリジナル) /