Garbage Collection

I noticed that my gameloop leaks a lot of memory unless I explicitly put in some collectgarbage(…) calls. Should we be looking at integrating this in the templates/hellolua or is it the intention that it will be bespoke per project?

I have noticed it. It seems the leak is caused by tolua++. I am not sure.

Just to clear things up, for me (at least) the getPosition()/setPosition() calls on my sprites generates a lot of 32byte objects. These are not leaked by lua. They’re just generated so fast/often per-frame the default Lua GC settings don’t ever get a chance to catch up!

For me, adding the lines :

collectgarbage( "setpause", 100) 
collectgarbage( "setstepmul", 5000)

Before the game-loop. Keeps the memory in-check with no apparent frame drop-offs, so no leaks :wink:

Nice solution!

ciaran jessup:

Where did you add these lines?

I am sorry, I haven’t seen:
Before the game-loop

no worries. You can actually place them anywhere (within the gameloop) … allowing you to adapt to your needs. Please also note some pull requests were submitted to reduce the initial footprint too :slight_smile:

@zhangxm @ciaranj
I added the code to my game and got stucked sometime when collect garbage.There is a better solution?

collectgarbage( "setpause", 130) 
collectgarbage( "setstepmul", 5000)

or pause gc when load big config




@yinjimmy gave a good suggestion, you can adjust the value you like, and i think you can manually trigger garbage collection when replacing a scene or some other places that you think it is suitable.