chaucer Posted March 18, 2018 Share Posted March 18, 2018 I've recently found something slightly odd when creating a texture from a canvas, I was hoping someone could help me understand what exactly is happening, as well as if theres a solution to the issue. The problem I'm encountering, is that anytime I create a texture from a canvas, and call... canvas.getContext( '2d' ); my ram consumtion seems to go higher than if I don't call the getContext function. This isn't the only issue though, as anytime i try to clear the texture, the ram that the texture consumed doesn't seem to be freed either. Here's a screenshot to show the comparision. In both examples, I've created a blank canvas with the size of 10,000x10,000( just for testing purposes ). The only difference in each example, is that the top screenshot does not call getContext, while the bottom one does. You can see quite a large difference in the amount of ram consumed, as well as that the memory isn't cleared in the bottom one, even after removing it's parent and destroying it. If anyone can provide any insight as to why this is happening or has a solution to the issue, I'd greatly appreciate it. Quote Link to comment Share on other sites More sharing options...
OSUblake Posted March 19, 2018 Share Posted March 19, 2018 In your screenshot you have a reference to the canvas element, so it will still be in memory. And I'm not 100% sure, but I don't think there will be any image data until you call getContext. A 10000 x 10000 bitmap will of course eat up some memory. chaucer 1 Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted March 20, 2018 Share Posted March 20, 2018 That's 10 5k monitors. That's at least 10k$ . Anyway, try "d=null" after all that. And there's no guarantee about when browser actually frees that memory. Also no guarantees about free videomemory, whether its still allocated or not. Try repeat that 10 times and see the result chaucer 1 Quote Link to comment Share on other sites More sharing options...
Exca Posted March 20, 2018 Share Posted March 20, 2018 After setting null you can force garbage collection from perfomance tab. Though I think that does not affect video memory. Not sure though. chaucer 1 Quote Link to comment Share on other sites More sharing options...
chaucer Posted March 20, 2018 Author Share Posted March 20, 2018 @ivan.popelyshev Haha, yeah, I don't actually use any canvas objects that size, I was just using it so that the ram usage was more visible, the issue happens to me on smaller images as well, it's just easier to see with a larger canvas. I'd previously tried setting the canvas to null, as well as setting it's size back down to 0 before doing so, I also tried as @Exca suggested, and tried forcing garbage collection, however my ram still does not free up, and again, it's only when the canvas.getContext('2d') is called, which really strikes me as odd, reguardless It's not that big of a deal I guess, mostly it's just a curiosity to me. Also the ram DOES eventually free up on it's own( just not all of it ) if i let it run for about 5 minutes. Also I just had another person try this out, and on their end it seemed to work fine for both examples, so it might just be something to do with hardware(?), since I've already checked drivers, and ran several scans to make sure everythings running smooth on my computer. Either way thanks for the words of advice, it's much appreciated Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted March 20, 2018 Share Posted March 20, 2018 ITs not odd, browser can remember RGBA state of canvas /image and then drop it, no guarantees about when it actually drops it. chaucer 1 Quote Link to comment Share on other sites More sharing options...
chaucer Posted March 20, 2018 Author Share Posted March 20, 2018 Interesting, I've still got a lot to learn about JS thanks for sharing this with me @ivan.popelyshev thanks for your time responding to my message, it's definitely been helpful. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.