Isn't THIS a reference to the bitmap object?
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];};So as long as this._cache[key] exists, the bitmap will still be in memory. The sprite will be removed, but not the bitmap. And I see nothing that removes it from this._cache except ImageManager.clear, which appears to never actually be called.
If this is how caching works then there could be serious performance issues with larger maps that contains lots of events. In theory when a scene is switched everything should be blown away and re built. It makes sense to cache for the web I suppose. but even then you'll have sever performance issues.
Another way that this should have been dealt with is a state, you update the state, like In ReactJS, and then read from it. It makes the application super fast and super responsive. With how they cache things here I fear that a map with 20+ events could cause serious lag, unless they are smart enough to not activate and or draw said events until the player is with in "eye distance" of those things.
So ... If we use that logic and apply it to how RPG maker caches things then its fair to say that caching wont be too much of an issue, because its only fetched when the player enters the area of said events, sprites and so on. Or when the player activates a window like pressing esc or chatting. (those things make sense to be cached)
About what were talking about here:
When things are popped off the scene or the a window is disposed it makes sense to cache them so we don't have to use precious resources to re-create them especially for rebuilding them. How ever as a programmer it makes sense that if you want to recreate them you pop them off the cache and let GC take care of them. The issue is that if you depend on x a lot then recreating x could cause performance issues.
So ...
Cache what you can, but know that at first creating the cache will be slow, maybe noticeably so. But after that things should be rather fast.
So in my understanding, when I made a bitmap for example and I want to remove it, by simply making a sprite go to null, makes it removed from the cache?
No, the variable you set to null was holding a reference to the Sprite object in memory. Assuming it's not referenced from anywhere afterwards, it will be deleted by the garbage collector. Now for the underlying Bitmap, this depends:
- If you loaded the image via new Bitmap(...) or Bitmap.load(...) and it was only referenced by the Sprite, the garbage collector will get it, too.
- If you loaded the image via ImageManager.load<...>, it's still referenced by the ImageManager and will stay in cache.
Ahh, that's getting clear. So is there a way we can tell ImageManager to ditch the whole Sprite for example when we terminate it? Or does leaving it as is won't affect the overall performance of the game?
you would find it in cache and delete it