Memory leak?

Discussion and feedback on Construct 2

Post » Thu May 30, 2013 2:49 pm

I'm building a metroidvania using Tiled and Rexrainbow's TMXImporter. The tiles are frames in a sprite object.

When a room is loaded the tiles are created, then 4 canvas objects and 4 empty sprite objects are created and stretched out to the size of the room. I then paste all the tiles into the canvases, then load the canvas images into the sprite objects (because WebGL and canvas don't go well together) and finally destroy all the tiles and canvases. Bada bing bada boom - hundreds of tiles are now 4 medium-sized sprite objects and performance is great. When all is said and done, the previous room is destroyed in its entirety.

However..

I started keeping track of RAM & VRAM and every time I load a new room these numbers go up - even if the room uses the exact same tiles and objects as the last.

What can I do about this? If you play the game for too long you'll surely run out of memory, and I'm not seeing "dump textures from memory" or anything like CC had so I'm starting to freak out a bit. Thanks for any help!Tokinsom2013-05-30 14:52:10
Image
B
242
S
29
G
13
Posts: 1,787
Reputation: 18,685

Post » Thu May 30, 2013 4:14 pm

I'm assuming you using Rojohound canvas. I don't know if the canvas plugin holds onto the created canvas or not, but you can try creating the canvas as global objects and re-using them. Just incase it's a canvas problem.

As I understand WebGL mode has an ability to reload based on layout. But I'm not sure canvas plugin does.
B
90
S
18
G
9
Posts: 2,455
Reputation: 15,013

Post » Thu May 30, 2013 4:23 pm

It's probably a leak in a third party plugin. It might not be, though - creating temporary canvases then dropping references to them does not necessarily release them, it only allows them to be garbage collected. GC might not happen for a few seconds, or even a few minutes, but it definitely will happen as soon as it starts running out of memory. So it might keep going up, then suddenly jump down when the browser decides it needs to clean up.
Scirra Founder
B
387
S
230
G
88
Posts: 24,249
Reputation: 192,450

Post » Thu May 30, 2013 5:17 pm

Alright the problem is indeed with the canvas plugin. I tried leaving the tiles as they were and VRAM stayed the same in between rooms. @R0j0hound is there anything that can be done about this on my end? Will WebGL support fix it?
Tokinsom2013-05-31 04:30:16
Image
B
242
S
29
G
13
Posts: 1,787
Reputation: 18,685

Post » Thu May 30, 2013 7:06 pm

[QUOTE=Tokinsom] @R0j0hound is there anything that can be done about this on my end? Will WebGL support fix it?
[/QUOTE] better ask him in his plugin thread.
B
18
S
5
G
4
Posts: 568
Reputation: 5,079

Post » Thu May 30, 2013 7:26 pm

Why not just export an image from Tiled?
That's essentially what you are doing with Canvas.
Image ImageImage
B
168
S
50
G
164
Posts: 8,228
Reputation: 105,575

Post » Thu May 30, 2013 7:46 pm

Thanks but that's not an option here, for many reasons.
Image
B
242
S
29
G
13
Posts: 1,787
Reputation: 18,685

Post » Fri May 31, 2013 2:08 am

@Tokinsom
The apparent memory leak and performance hit when using the canvas plugin with webgl on is one and the same issue. Unfortunately I can't think of anything that would help it on your end. In theory rewriting in proper webgl support would fix the problem of performance and memory inefficiency. However in the mean time the memory usage can be ignored as the the extra memory will be GC'd as needed.

As I wrote that I realized some ways you could possibly reduce the memory usage of the canvas object.

1. Make the canvas invisible. You said it's only used to draw to and then it's image is copied over to a sprite. If the canvas is never drawn then its image never needs to be copied to the gpu so less memory is used.

2. Use one global canvas and re-use it as needed. Each canvas object uses it's own html5 canvas so it may possibly use less memory if you use only one.
B
91
S
31
G
103
Posts: 5,235
Reputation: 67,756

Post » Fri May 31, 2013 4:40 am

I see. Well, will leaving it up to GC cause any problems like stuttering or over-working hardware or anything?

Also the canvases have been invisible this whole time; doesn't seem to make a difference.

As for the global canvas..not sure how that'll work since it still needs to be created and destroyed each time a room is loaded to prevent performance issues. I did manage to use only 1 canvas for all layers instead of 1 per layer, though..unfortunately that doesn't make a difference either.

I hope it won't take too much longer for the WebGL canvas. This is only one of the many many things I'll be using it for!Tokinsom2013-05-31 04:43:37
Image
B
242
S
29
G
13
Posts: 1,787
Reputation: 18,685

Post » Sat Jun 01, 2013 9:14 am

I don't understand why you can't use suggestion 2. To use a global canvas.

If your creating, then destroying per room. Then all you need to do is clean and draw the new room on the canvas per room.
B
90
S
18
G
9
Posts: 2,455
Reputation: 15,013

Next

Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 6 guests