Jquery .remove() + garbage collector or clear.

0 favourites
From the Asset Store
Basics sprites and tilesets to build a platformer game or prototype
  • Hi, is my first game and i have a problem.

    I call the game with jquery ajax in a web and put in a div with the jquery function "append()".

    When the game has ended i call a jquery function "remove()" to clear the html with the canvas in the div but the memory usage with the browser not decrease.

    With the "remove()" the div is empty but the memory usage not.

    How can I do for remove this canvas and the memory usage for this?

    Sorry for my english.

    Greetings.-

  • That's because C2 game is still in the windows memory space.

    I'm not sure what C2 call's itself in the Windows name space. but if you want clear C2 you need to clear memory used. What you are currently clearing is the Canvas which is a render target and not the game logic, video or audio.

  • Perhaps through the use of an iframe ? afterwords either remove the iframe or load something else.

  • If i use a iframe I can't close the iframe in the div when the game is finish And then use a jquery function to continue with another options of the site

    I need a function o somethings to remove or clear the memory usage with c2 when i remove the div.

    Sorry for my english.

    Greetings.-

  • you can load the Iframe in a div dynamically just like any other html.

    You could first load a blank page (I think this frees the memory) then simply clear the content of the div holding the iframe :) (load a new iframe of set some text etc)

  • Removing the canvas element doesn't remove all the memory allocations made by the game engine in Javascript. It's designed to be used in an iframe, there's no good way to clean up the whole engine otherwise.

  • Removing the canvas element doesn't remove all the memory allocations made by the game engine in Javascript. It's designed to be used in an iframe, there's no good way to clean up the whole engine otherwise.

    I think he means, from a webpage where he included a cs2 program, where I mention stuffing it in your own iframe and calling the index.html file of your game.

    Wouldnt loading another page in that iframe clear up the memory used by the cs2 program ? (it should, otherwise browsers be clogging up everywhere)

  • The problem is if i use iframe i don't have interactivity CS2 / SITE.

    I tested with iframe but the memory problem persist.

    example: in firefox with when consume 2.5gb of memory the firefox crash.

    Any idea to clear memory? <img src="smileys/smiley19.gif" border="0" align="middle" />

    Sorry for my english.

    Greetings.-

  • oh, it stays :o I didnt know that

    Here is a page with reference about memory leaks from javascript, not sure one of the suggestions/solutions work, but perhaps good reading for what your looking in to.

    tut memory leaks javascript

  • Changing the URL of the iframe, or removing the iframe entirely, will remove all the memory the game uses. Since Javascript is a garbage-collected language it's possible it doesn't all disappear immediately. You might need to wait for it to get cleaned up.

  • Sorry but I think the iframe is a very bad practice:

    1- Lose the interaction with the site.

    2- Consume the same memory, and for user waiting 5 or 10 minutes for browser decide to empty the memory is horrible.

    3- We need interaction Normal Web With the C2 for a better designs or web aplications

    I have a magic temporary solution :P (C2 MAGIC).

    When finish the game I go to a clear layout with black background and On start of layout execute the javascript fuction to remove, and the C2 consumition are reduced to a minimun.

    Thanks guys for the intension to help me.

    Sorry for my english.

    Greetings.-

  • 1- Lose the interaction with the site.

    Thats only true if you dont know how to do it ^_^

    There are simple javascript approaches to getting info from a top window from within the iframe, such as .parent()

    You can even call functions from an iframed window which are defined in the page holding the iframe.

    I dont see how your trick would work any different by loading a less cpu intense layout ... the project is still loaded in to memory, images and all, from all layouts.

    An export to html5 stil has a simple index file which you can fill with any kind of javascript or even PHP if you like :)

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • I don't like iframes

    With this trick can reduce the memory usage of 750 to 50 mb. I think it's a good trick :P

  • iframes work fine. It should clear memory within seconds, not minutes. It should interact with the page just fine.

  • I don't know why but if I use a iframe the custom loader doesn't work.

    The loader bar do nothing.

    I use "clamp (0, (loadingprogress * 488.5), 488.5)"

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)