jzrake / lunum

Numeric arrays for the Lua programming language
35 stars 6 forks source link

manual collectgarbage() call maybe needed for large arrays #4

Closed jzrake closed 12 years ago

jzrake commented 12 years ago

The present design of Lunum is such that Lunum arrays are directly malloc'ed and then free'd by the __gc metamethod. Since lua_newuserdata is never used to allocate the array buffer itself, Lua thinks that it's using far less memory than may actually be being used, and so garbage collection cycles are not entered as often as they should be. Note that technically this is not a memory leak; all memory is cleaned up when Lua closes. In the future, this will change so that array buffers are Lua objects and therefore recognized by the garbage collector as accounting for total memory used by the Lua state.

For now, a call to collectgarbage() at the end of any loops that allocate large arrays will take care of poor performance.

jzrake commented 12 years ago

This issue has been resolved by commit 5e88f6114e141aeee994803416a825554bba9edd which is presently in the development branch.

jzrake commented 12 years ago

This fix has now become part of the master (release) branch in bd5faf16cb674828b8ab0fb1bdfd84852c774a1d.