Memory leak?

0 favourites
  • 11 posts
From the Asset Store
Test and challenge your memory in this amazing Christmas themed memory game!
  • 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!

  • 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.

  • 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.

  • 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?

  • R0J0hound is there anything that can be done about this on my end? Will WebGL support fix it?

    better ask him in his plugin thread.

  • Why not just export an image from Tiled?

    That's essentially what you are doing with Canvas.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thanks but that's not an option here, for many reasons.

  • 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.

  • 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!

  • 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.

  • jayderyu R0J0hound

    Unless I'm doing something wrong...

    -Making the canvas global doesn't change a single thing.

    -Making the canvas invisible doesn't change a single thing.

    -Using 1 canvas instead of 4 doesn't change a single thing.

    -Clearing the canvas instead of destroying and creating a new one doesn't change a single thing.

    The whole *game* takes place in a single layout and the rooms are dynamically loaded and destroyed within that single layout, so I don't see how making the canvas global is supposed to affect anything here. I appreciate the help but as originally stated - I don't think there's anything that will work on my end. It seems to be a problem with the plugin and that's that...

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