Memory efficient javascript
- Started
- Last post
- 9 Responses
- Stugoo
Im building a sideshow that needs to load in and drop dynamic content at regular intervals over an will run over long period of time (12-24 hours).
Does anyone have any examples or reading material to handle this sort of thing?
- Stugoo0
Excuse my grammar :
... A sideshow that will load in rotate dynamic content then drop it out after a certain time, but be efficient on the memory enough to last for a full day without a reload.
- ETM0
Sooo.... content within the slideshow expires at different intervals, and the script is tight enough as not to bloat and crash.
- monNom0
here a book:
http://oreilly.com/server-admini…
- ********0
A slideshow.
- uan0
check client time. load from clientTime/image.jpg.
efficient on the memory...without reload...dynamic content...sounds impossible imo...maybe a spritesheet with all images in it and then offset by the hour or something...
really depends on the size of the images I guess.
- monNom0
^ a huge sprite sheet is probably going to be more trouble than individual files unless we're talking a clock or something smaller.
I'd suggest something like
var myImage = new Image()
myImage.src = 'url';
// do things with the image, either append to DOM or draw to canvas
//when done with it
delete myImage();that should free up the memory used by the image when the garbage collector comes around.
otherwise, your only problem might be a long running loop, but my link above gives strategies for that.
- Weyland0
just obey closure and maybe just change src attribute of a few layers instead of having new elements being swapped in the DOM to keep the memory use low
- ********0
- monolith0
deleting DOM elements sometimes still doesn't make GC release it from the memory causing a memory leak. The best approach, especially for mobile is to load in 1px image instead of the image you have and then delete. Forcing 1px image to replace the big one will automatically trigger the GC.