pgimeno wrote: ↑Wed Sep 21, 2022 7:11 pm
pyxledev wrote: ↑Wed Sep 21, 2022 6:48 pm
Aw man, I thought the garbage collector could take care of this
It will eventually,
BrotSagtMist wrote: ↑Wed Sep 21, 2022 10:17 pm
I does not.
I have a textbox here with free zooming and font choosing options.
It can easily eat a few gigs of ram.
Automatic GC will most likely never take care of it, or at least i was never been able to trigger it.
It will eventually, if it has a chance before the process runs out of memory.
Proof:
Code: Select all
local i = 1
repeat
love.graphics.newFont(6)
if i % 500 == 0 then
print(collectgarbage("count"))
end
i = i + 1
until false
Example output:
Code: Select all
706.130859375
792.630859375
903.130859375
965.630859375
913.486328125
914.189453125
976.689453125
1039.189453125
1101.689453125
583.939453125
646.439453125
708.939453125
771.439453125
834.330078125
896.830078125
959.330078125
1021.830078125
1252.517578125
1315.017578125
1377.517578125
1440.017578125
1502.517578125
766.205078125
828.705078125
891.205078125
953.705078125
1016.205078125
1078.705078125
1141.205078125
1203.705078125
1266.205078125
1328.705078125
1391.205078125
1453.705078125
1491.142578125
1553.642578125
1616.142578125
1678.642578125
1741.142578125
1803.642578125
1866.142578125
1928.642578125
1991.142578125
2053.642578125
1383.580078125
827.205078125
889.705078125
664.205078125
726.705078125
885.205078125
947.705078125
1010.205078125
1072.705078125
1327.205078125
1389.705078125
1452.205078125
1471.892578125
1534.392578125
1596.892578125
1659.392578125
1721.892578125
1784.392578125
1846.892578125
1909.392578125
1312.955078125
814.580078125
877.080078125
939.580078125
1002.080078125
1064.580078125
1127.080078125
997.580078125
1060.080078125
1314.580078125
1377.080078125
1439.580078125
1462.580078125
1525.080078125
1587.580078125
1650.080078125
1712.580078125
1775.080078125
1837.580078125
1900.080078125
1962.580078125
780.580078125
843.080078125
905.580078125
968.080078125
1030.580078125
1093.080078125
963.580078125
1026.080078125
1280.580078125
1343.080078125
1405.580078125
1427.955078125
1490.455078125
1552.955078125
1615.455078125
1677.955078125
1740.455078125
1802.955078125
1865.455078125
1927.955078125
1320.455078125
813.080078125
875.580078125
938.080078125
1000.580078125
1063.080078125
933.580078125
996.080078125
1058.580078125
1313.080078125
1375.580078125
...
These values are in KB, so it maxes out at around 2 MB. However, these are the
Lua-side userdata pointers; the actual C++-side font data is not accounted for in that size.
The fonts created by that test program are small, so they use little memory and Lua has a chance to collect garbage before the size grows to a dimension that doesn't fit in the available memory. If they are big, of course Lua will not notice that RAM usage is disproportionate and that cleanup is necessary.
I may be wrong, but I believe that's the main reason why
Object:release was introduced. What it does is free the C++-side memory while leaving the Lua-side object intact.
Of course there's another way which would be to invoke the garbage collector manually in the loop.
Anyway, the cleanest solution if the same fonts are going to be used again and again, is memoization.