Page 2 of 2

Re: Object recycling tips

Posted: Wed May 11, 2016 10:20 am
by cval
marco.lizza wrote: But one should also try and reuse the userdata types, more than the objects themselves.
It is trivial for a particle emitter, since you can set any value to previously created one before with no problem, but i'm not sure about physics. Few examples - i found no way to change shape's dimensions or local points for it to be reused somewhere, and it also says that on every fixture created, shape is copied. So for now, it seems like, simple stack-structured pool would not work for physics.

So to recap this - default (strong) tables are collected only when there is no more references to them (and collection cycle happens), and weak tables can be collected on next collection cycle. Am i right?

Re: Object recycling tips

Posted: Wed May 11, 2016 10:36 am
by marco.lizza
cval wrote:So to recap this - default (strong) tables are collected only when there is no more references to them (and collection cycle happens), and weak tables can be collected on next collection cycle. Am i right?
It isn't the table the object of the garbage-collection, but the objects/functions/whatever the are referring to by means of keys and/or values.

To sum things up again, weak-tables references doesn't count when marking "used" resources. If the last reference to an object is stored in a weak-values table (for example), at the next GC cycle it will be disposed.