Jquery .remove() + garbage collector or clear.

For developers using the Construct 2 Javascript SDK

Post » Tue Dec 24, 2013 6:04 pm

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.-
B
5
Posts: 21
Reputation: 375

Post » Tue Dec 24, 2013 9:58 pm

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.
B
90
S
18
G
9
Posts: 2,455
Reputation: 15,013

Post » Tue Dec 24, 2013 10:52 pm

Perhaps through the use of an iframe ? afterwords either remove the iframe or load something else.
Who dares wins
B
57
S
17
G
21
Posts: 1,878
Reputation: 19,562

Post » Tue Dec 24, 2013 11:48 pm

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.-
B
5
Posts: 21
Reputation: 375

Post » Wed Dec 25, 2013 7:22 am

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)
Who dares wins
B
57
S
17
G
21
Posts: 1,878
Reputation: 19,562

Post » Wed Dec 25, 2013 10:30 am

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.
Scirra Founder
B
387
S
230
G
87
Posts: 24,249
Reputation: 192,240

Post » Wed Dec 25, 2013 10:58 am

[QUOTE=@Ashley] 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.[/QUOTE]


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)

lennaert2013-12-25 10:59:01
Who dares wins
B
57
S
17
G
21
Posts: 1,878
Reputation: 19,562

Post » Wed Dec 25, 2013 1:41 pm

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?


Sorry for my english.


Greetings.-
B
5
Posts: 21
Reputation: 375

Post » Wed Dec 25, 2013 2:58 pm

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

Who dares wins
B
57
S
17
G
21
Posts: 1,878
Reputation: 19,562

Post » Thu Dec 26, 2013 10:55 am

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.
Scirra Founder
B
387
S
230
G
87
Posts: 24,249
Reputation: 192,240

Next

Return to Javascript SDK

Who is online

Users browsing this forum: No registered users and 0 guests