I have 16Gb of ram on my computer. I have allocated 768mb to the WebGL Memory Size.
My game .datagz is 100mb.
My game always works fine and I’ve never had memory issues.
Today I had someone testing my game complaining they got an out of memory error on my game. And this user is running FireFox 49 on Windows 7, yet they also have 16Gb of RAM.
How could this be possible? Could it be they had too many other programs open? Or they had too many browser windows open?
This is not the bitness of the operating system that matters, but the bitness of the browser that the user is using. For example, many users still run 32-bit Firefox on a 64-bit system, which means that the theoretical maximum memory available for the browser process is 4GB. Note that the heap memory should also be continuous, while allocation/deallocation of big chunks can eventually make this memory fragmented. So even though there might be lot of free memory available for the browser process within those theoretical 4GB, there might still be no continuous block of 768MB. The problem often occurs when the game tab is reloaded multiple times.
P.S. In case of game portals, this problem can be partially resolved by reusing the heap (i.e. when user switches the game, the heap can be reused instead of being reallocated).
Note that normally this only applies to cases when you have more than one game on your website that user can switch between. However, it might also be considered in cases when a runtime error occurs and the user is given an option to reload the game.
The heap is just an ArrayBuffer and therefore can be preallocated and resued. You can provide the preallocated buffer as a buffer property of the Module object in the index.html, for example:
var preallocatedBuffer = new ArrayBuffer(268435456);
var Module = {
buffer: preallocatedBuffer,
TOTAL_MEMORY: preallocatedBuffer.byteLength,
errorhandler: null,
compatibilitycheck: null,
dataUrl: "Release/build.data",
codeUrl: "Release/build.js",
memUrl: "Release/build.mem",
};
Note that ArrayBuffer is a transferable object, so you are able to transfer it between the main frame and iframe, or even between different tabs (without reallocation or copying) using the following code (the destinationWindow will receive a message event):destinationWindow.postMessage(buffer, "*", [buffer]);Just keep in mind that once the buffer is transferred to another window it can no longer be accessed from the source window.
A common scenario could be the following. A portal page allocates a large enough buffer, runs the selected game in an iframe and transfers the buffer to that iframe. Once the user stops the game or selects another game, the buffer is transferred back to the portal page, and the iframe is destroyed. Restarting the game is basically the same as selecting the game twice.