I'm looking at the Cache module and I see that when an image is loaded, it gets stored in a hash.
However, does it ever get deleted when it's no longer needed? Or do all images just get cached forever until you restart the game (at which point the cache is cleared and GC'd)?
By "no longer needed" I mean it hasn't been accessed for a sufficiently long time.
Does RM cache clear old data?
● ARCHIVED · READ-ONLY
-
-
Wow!
VERY interesting question.
And if garbage collection is not applied, this should be fixed or optimized somehow.
My bet is that everything is stored in the heap until the class instance is destroyed.
So question is, if I am right, which class stores that hash? And of course... when is this class instance destroyed? -
It is kept in the RAM until the Game.exe closes.
-
Ouch!It is kept in the RAM until the Game.exe closes.
-
Wow, that'll slow down a computer big time and may cause some undesirable crashes.
-
It needs A LOT of pictures to achieve that by RAM overloading. Or very little RAM...Wow, that'll slow down a computer big time and may cause some undesirable crashes.
Still it would be nice not overloading resources for no apparent reason.
But to be honest, many scripts that dispose cache, make VX Ace work better.
I don't know how exactly (and why) VX Ace handle pictures, but if there is space for improvement, someone should do something about it right?
:p -
Not really. Images are loaded when they are first required/requested, and worst case scenario would be having the equivalent size of the Graphics folder loaded into the RAM alongside other objects used by the game. Most computers these days have at least 2 GB of RAM and most RPG Maker these days don't go over 500 MB in Graphics folder size (most of them way less than that, music being the most influential factor in total download/game size).Wow, that'll slow down a computer big time and may cause some undesirable crashes.
Cache improvement/mods for special cases is a good idea, but for the common use of the program, it is not needed and may even be detrimental to the gameplay experience. -
In addition to what Source said, it's worth noting that most RPG Maker games get astronomical file sizes due to audio resources such as background music, and RPG Maker actually streams BGM files into memory in chunks rather than loading them all at once. Smaller audio resources (such as SEs) are loaded all at once into memory and then disposed of, but this shouldn't ever present a problem.
"The more you know," and all of that. -
Those are all great information, Source and Solistra! Thanks for that! ^^
I would just add another thing to the RAM issue.
It is true that most computers have at least 2GB of RAM, and I am fairly certain that most devs here have at least double of that.
The thing is, Windows 7/8 uses approximately 1GB of RAM, leaving less than 1GB more other uses.
If someone happens to have an internet browser on linked to some social networks, youtube, etc, while playing music files, while editing documents, while playing games, if may be a bit more of an issue.
In case you're wondering who does this kind of multi-tasking, I'd say a lot kids and teenagers, except the games tend to be other than RM games.
Just a case scenario, but I do realize how extreme it may sound. ^^
Also, I'm not sure if anyone knows the maximum RAM useable by VX Ace at any given time. -
Most RPG Maker Games easily have more than 500 MB uncompressed graphics. Caching is a typical memory vs. time consumption.
Try running your game with the Task Manager open. If the memory consumptions stays in the 40-100 MB range then you probably do not need to do anything.
Should it continue to rise, then it might become a problem in the future. I have seen an RM game going above 700 MB in memory usage.
If you measure a potential memory consumption issue, then clearing the cache can be an option. (RGSS1 code, dunno if it is the exact same in RGSS2/3)
RPG::Cache.clear
Only use this if there is a problem. Also, if you know you have a one-time picture, a bitmap that should only be shown once. Don't put it in the cache.
*hugs*
- Zeriab -
My game precaches animations and hidden it in splash screen while precaching it. And it takes up to 300mb.
The good thing is whenever I want to play animation, there is no noticable lag / frameskip while playing the animation
Some of the images are disposed. Look at how draw_face at the Window_BaseI'm looking at the Cache module and I see that when an image is loaded, it gets stored in a hash.
However, does it ever get deleted when it's no longer needed? Or do all images just get cached forever until you restart the game (at which point the cache is cleared and GC'd)?
By "no longer needed" I mean it hasn't been accessed for a sufficiently long time.
def draw_face(face_name, face_index, x, y, enabled = true) bitmap = Cache.face(face_name) rect = Rect.new(face_index % 4 * 96, face_index / 4 * 96, 96, 96) contents.blt(x, y, bitmap, rect, enabled ? 255 : translucent_alpha) bitmap.dispose # <-- This line dispose the cached faceset endIt's actually depends on how the script handled the bitmap. Some of them get disposed, some may not.
The interesting thing from bitmap is if you lose the variable that referenced to the bitmap, it get disposed instantly, unlike Sprite / Window / Plane / Viewport
Look at how cache get cleared
def self.clear @cache ||= {} @cache.clear GC.start endThough, honestly I'm not sure if it was because GC.start. -
interesting point your code is almost similar but contrary to XP the VX/ACE cache is not a RPG class so this will not affect but I think the good way isMost RPG Maker Games easily have more than 500 MB uncompressed graphics. Caching is a typical memory vs. time consumption.
Try running your game with the Task Manager open. If the memory consumptions stays in the 40-100 MB range then you probably do not need to do anything.
Should it continue to rise, then it might become a problem in the future. I have seen an RM game going above 700 MB in memory usage.
If you measure a potential memory consumption issue, then clearing the cache can be an option. (RGSS1 code, dunno if it is the exact same in RGSS2/3)
RPG::Cache.clearOnly use this if there is a problem. Also, if you know you have a one-time picture, a bitmap that should only be shown once. Don't put it in the cache.
*hugs*
- Zeriab
Cache.clearEDIT : but for be sure for reduce Any picture Cache conversation who can provoke slowdown
people should always do that for each picture who are not usefull at all
def dispose_sprite@sprite.dispose@sprite.clearend#general clear of the CacheCache_refreshdef Cache_refreshif Cache.content >= 130.mbCache.clearendendyou will need to define what is MB but this a way for be sure you game not encounter crash du ram use -
Worst case should be much higher than the disk size of the Graphics folder because most people (at least, I'd like to think that) do not use uncompressed graphics. The actual size taken by most graphics in memory are probably 2x to 4x the stored size.Not really. Images are loaded when they are first required/requested, and worst case scenario would be having the equivalent size of the Graphics folder loaded into the RAM alongside other objects used by the game. Most computers these days have at least 2 GB of RAM and most RPG Maker these days don't go over 500 MB in Graphics folder size (most of them way less than that, music being the most influential factor in total download/game size).
My assumption is that raw bitmaps are being stored in memory.
Where is the cache clear being called? I did a search and didn't see anything.The interesting thing from bitmap is if you lose the variable that referenced to the bitmap, it get disposed instantly, unlike Sprite / Window / Plane / Viewport
Look at how cache get cleared
def self.clear @cache ||= {} @cache.clear GC.start endThough, honestly I'm not sure if it was because GC.start.
Unless the `clear` method is special and is called automatically or something.
The cache doesn't seem to automatically dispose things either
Code:The image is not included in the cache if it's disposed, causing it to be reloaded, but it doesn't seem like it gets removed. Is this something the GC should handle? To figure out that certain hash entries should be disposed?def self.include?(key) @cache[key] && !@cache[key].disposed?end