Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Memory issue with HTML5 - any ideas? — Gideros Forum

Memory issue with HTML5 - any ideas?

NinjadoodleNinjadoodle Member
edited July 2016 in General questions
Hi guys

I'm currently testing the HTML5 version of my game (on Desktop), and I've noticed that after I cycle through the levels a few times (once I reach level 10, it goes back to 1), all I get is a black screen.

From the warnings the log window is giving me, I'm pretty sure its a memory issue. I have 1 atlas per level, but I wonder whether the memory keeps stacking up instead of getting cleared.

Anybody know what I can do to fix this?

Thank you heaps in advance!!

Comments

  • antixantix Member
    @Ninjadoodle, so how are you managing your atlases?
  • NinjadoodleNinjadoodle Member
    edited July 2016
    Hi @antix - so the only thing i'm doing is loading the atlas at the start of each level and making it a property of the scene.

    There are no problems in the native version, and the memory issues only arise in HTML5 (probably because things are treated / loaded differently).
  • antixantix Member
    @Ninjadoodle, ahh hmm. Hopefully the HTML5 guy will weigh in here soon :)
  • hgy29hgy29 Maintainer
    @Ninjadoodle, do you force garbage collection between your levels ? Html5 uses a fixed memory size, so better enforce memory recovery yourself than relying on Lua, the latter may be triggered too late.
  • NinjadoodleNinjadoodle Member
    edited July 2016
    Hi @hgy29 - Thank you for your reply. Nope I'm not doing this, as I thought the memory gets cleared by itself when objects are a property of the scene.

    What would be the easiest way to garbage collect?

    I tried putting - collectgarbage() at the start of my level, and before changing to the next scene.
  • I use a timer:
    	self.t = 0
    	self.miliT = Timer.new(100, 10)
    	self.miliT:addEventListener(Event.TIMER_COMPLETE, self.onTimerComplete,self)
    	self.startTime = 0
    function ingame:onTimerComplete(event)
    	self.miliT:reset()
    	self.t = self.t + 1
    	self.miliT:start()
    	collectgarbage()
    end
    The self.t is used for the ingame clock so I garbage collect once a second while updating the seconds text for the ingame clock.
    I would get a second opinion incase this is a terrible idea somehow but it works for me :)

    Likes: Ninjadoodle

    +1 -1 (+1 / -0 )Share on Facebook
  • hgy29hgy29 Maintainer
    edited July 2016 Accepted Answer
    Putting it at the very start of your level, after cleaning up previous level and before loading assets of the next one, should be enough. If this doesn't work then maybe you have a memory leak somewhere ? You may want to check memory usage right after your gc to ensure it is consistent accross level changes. Someone on the forum contributed leaky.lua which could help in that case.

    Also on HTML5 temp files take memory, if you use them be sure to remove created files afterwise.
    +1 -1 (+2 / -0 )Share on Facebook
  • SinisterSoftSinisterSoft Maintainer
    This works for me, at the beginning of a level.

    Likes: Ninjadoodle

    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    https://deluxepixel.com
    +1 -1 (+1 / -0 )Share on Facebook
  • NinjadoodleNinjadoodle Member
    edited July 2016
    Hi @hgy29 - I've tested this and I haven't had any more black screens. Thank you for your help!

    @billydb and @SinisterSorf - thank you for the tips guys!
Sign In or Register to comment.