Will too much memory usage become a problem in games?

I'm looking at the the way ImageManager is implemented and it uses a cache to store objects. Example

ImageManager.loadNormalBitmap = function(path, hue) { var key = path + ':' + hue; if (!this._cache[key]) { var bitmap = Bitmap.load(path); bitmap.addLoadListener(function() { bitmap.rotateHue(hue); }); this._cache[key] = bitmap; } return this._cache[key];};Since this is meant to be the cache, it's meant to stay around for awhile.As you load images, they get cached.

At some point, if you load lots and lots of images, you're going to end up using a lot of memory.

I'm sure eventually you're going to run into problems?

I don't know if audio or other resources have a similar issue since I haven't looked at those yet.
I've been wondering about this myself. Especially considering mobile devices can run into memory problems quite easily.
You are probably right. Though, I've noticed many programs don't seem to care about memory allocation anymore, as they think everyone has all the memory in the world, so why bother?

And that is also why I find I now have to close and restart my internet browsers about every 4 hours, else they are using up 500K memory easy.
You are probably right. Though, I've noticed many programs don't seem to care about memory allocation anymore, as they think everyone has all the memory in the world, so why bother?

And that is also why I find I now have to close and restart my internet browsers about every 4 hours, else they are using up 500K memory easy.
With how much Ram you can easily stick in a desktop nowadays, I think people have gotten lazy in memory optimization yes. Regarding Hime's question though, I have to wonder...Would there be any way to purge unused assets? Or load them on a per-map/per battle basis? Admittedly yes, it would probably result in load times, but with low memory devices like mobile phones, this would pretty much be a requirement for anything that used a lot of resources.
I suppose if you wanted to implement a cache-collection system, you should be able to implement a timer that loops through the cache periodically, say maybe once per ten seconds, but probably longer, maybe only on map/scene change, go through each item, while maintaining a list of the last time each file was accessed by aliasing the load functions and storing Date objects in a list for each filename. If the last time a file was accessed is greater than a defined threshold, destroy the cached copy.

Now, the method I just described is a bit of a dumb method. It doesn't know the amount of memory available, how much it's necessarily using (though you can easily calculate that by checking the length and width of each image as you loop through, multiply them together, and then multiply by 4 for total bytes of memory used (mult by 4 because each color is rgba)), nor how much i sbeing requested. One possible way you might be able to get information on how much is available and how much is used is through chrome://memory-internals/, which has a little 'update' button that will check chrome's memory usage, and then have a JSON representation available in a small textbox, as well as displaying it on the screen. If you can find a way to press the button pragmatically and then grab the JSON output, you should be able to compare available memory to used memory and remove files accordingly. However, in this case you'll have to keep in mind that this will only work on the chrome web browser, the desktop clients, and maybe android ports. Other browsers and iOS would have to be switched to 'dumb' mode.

But if you have any other ideas, I'm interested in hearing them, as creating a 'dumb mode' cache cleaner wouldn't be hard at all. 
Guys, Its worse than that. Removing _cache wont help at all, because you have to manually free them from webgl context.
I suppose if you wanted to implement a cache-collection system, you should be able to implement a timer that loops through the cache periodically, say maybe once per ten seconds, but probably longer, maybe only on map/scene change, go through each item, while maintaining a list of the last time each file was accessed by aliasing the load functions and storing Date objects in a list for each filename. If the last time a file was accessed is greater than a defined threshold, destroy the cached copy.

Now, the method I just described is a bit of a dumb method.
It doesn't sound too bad. It hits two points of using a cache

1. The last time it was accessed

2. How often it's accessed

And you clear out anything that's too old or too rarely used.

Still better than just keeping it in cache all the time 😛

Web browsers also have their own caching mechanism, so even if something is cleared from the game cache, it shouldn't require users to send a request to some remote location just to get the file again unless they explicitly disable caching on their system.

Guys, Its worse than that. Removing _cache wont help at all, because you have to manually free them from webgl context.
I'm looking at some of the scenes and they don't do any clean-up

Scene_Base.prototype.terminate = function() {};Scene_Map.prototype.terminate = function() { Scene_Base.prototype.terminate.call(this); if (!SceneManager.isNextScene(Scene_Battle)) { this._spriteset.update(); this._mapNameWindow.hide(); SceneManager.snapForBackground(); } $gameScreen.clearZoom();};From the sounds of it, you need to explicitly call some sort of `free` or `destroy` methodLooking at this page, you have to manually call destroy for sprite/texture objects, but when I run a search through the rpg_sprites.js, there is no reference to destroy.

So, memory leak?
From the sounds of it, you need to explicitly call some sort of `free` or `destroy` methodLooking at this page, you have to manually call destroy for sprite/texture objects, but when I run a search through the rpg_sprites.js, there is no reference to destroy.

So, memory leak?

Without checking it and just thinking about it, I don't really think so. It doesn't free any resources, but it also doesn't recreate them. Once they're in the cache they stay there. If the same files are needed and were loaded earlier, they'll be available in the cache. Similarly to how  worked in Ace, disposing a bitmap from the cache caused issues because the cache returns a reference to a stored bitmap, not a copy of it. freeing your copy will completely wreck any other attempt to get the same image.
So, memory leak?
Yep, every time Spriteset_Map is created, it creates two textures of screen size that wont be freed if renderer uses webgl context.
when you use goto, woudn't the gc actually release the objects ?
The scene is not stored anymore anywere...

But yes, they should have freed resources anyway
when you use goto, woudn't the gc actually release the objects ?

The scene is not stored anymore anywere...

But yes, they should have freed resources anyway
Garbage collector doesnt work with webgl objects,we need to call destroy() method on every texture/framebuffer manually.
Interesting topic, I will have to keep this in mind in the future when my project gets bigger...

in AIR I controlled use of memory with dispose method, I'm sure in MV there is a way to control that, since there are no hidden classes, and one way or another you can "dispose/destroy" or w/e term they use here...

or maybe the game already has some kind of cache limit which auto-cleans itself above a certain threshold?
Garbage collector doesnt work with webgl objects,we need to call destroy() method on every texture/framebuffer manually.
Then as of here.

This may patch it:

Code:
(function () {function _generalDestroy =  function() {    for (var x in this) {      // we should not free bitmaps automatically because the cache loader may mess with us,       //we would have to destroy them manually      if (this[x] && this[x].destroy && (!(this[x] instanceof Bitmap)) ) {         this[x].destroy();      }    }    if (this.children) {      this.children.forEach(function (i) {            if (i && i.destroy) {            i.destroy();          }       });    }} Bitmap.prototype.destroy=_generalDestroy;Sprite.prototype.destroy= _generalDestroy;TilingSprite.prototype.destroy = _generalDestroy;Window.prototype.destroy= _generalDestroy;WindowLayer.prototype.destroy = _generalDestroy;Tilemap.prototype.destroy =_generalDestroy;Spriteset_Map.prototype.destroy = _generalDestroy;Spriteset_Battle.prototype.destroy = _generalDestroy;Scene_Base.prototype.terminate = _generalDestroy; Scene_Base.prototype.terminate = _generalDestroy; })();
Then as of here.

This may patch it
As I said in github, Im not sure yet 🙂

Guys, whoever want to participate in that fix - please join that thread in github. I'm sure we'll find solution for both vanilla and pixiv3 versions.
They probably won't have a github account.

Most of them don't want/need one.

But as I told you before, you should try to make other people write as less as they can, and they only use between scenes Bitmaps and Audio files...
Hmm, looks like this would mess with my popup plugins. But i thought about switching to an observer pattern, anyway.
I already encounter out of memory issues on smart phones and tablets. My game is pretty small, just a few small rooms and one big overworld map. Both use Firefox browsers (couldn't get it to run on Chrome-based browsers.) The crash usually happens when switching maps.

Large games with many resources shouldn't be a problem in itself. Many Android / iOS games are huge, sometimes up to a 1 GB. And they don't crash or get out of memory issues even after hours of play. My simple RMMV game crashes after a few map transfers. So you guys are right. It's either RPG Maker's map handling or WebGL's limitations.

Original thread: https://forums.rpgmakerweb.com/threads/will-too-much-memory-usage-become-a-problem-in-games.48163/