Does RM cache clear old data?

Tsukihime

Veteran
Veteran
Joined
Jun 30, 2012
Messages
8,564
Reaction score
3,846
First Language
English
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.
 
Last edited by a moderator:

_Shadow_

Tech Magician Level:
Moderator
Joined
Mar 2, 2014
Messages
4,078
Reaction score
2,654
First Language
Greek
Primarily Uses
RMMZ
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?
 
Last edited by a moderator:

_Shadow_

Tech Magician Level:
Moderator
Joined
Mar 2, 2014
Messages
4,078
Reaction score
2,654
First Language
Greek
Primarily Uses
RMMZ
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...

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
 

♥SOURCE♥

Too sexy for your party.
Veteran
Joined
Mar 14, 2012
Messages
693
Reaction score
411
Primarily Uses
Wow, that'll slow down a computer big time and may cause some undesirable crashes.
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).

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.
 

Solistra

Veteran
Veteran
Joined
Aug 15, 2012
Messages
593
Reaction score
247
Primarily Uses
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.
 

Susan

Veteran
Veteran
Joined
Sep 1, 2014
Messages
2,748
Reaction score
8,346
First Language
No idea...
Primarily Uses
RMMV
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.
 

Zeriab

Huggins!
Veteran
Joined
Mar 20, 2012
Messages
1,268
Reaction score
1,422
First Language
English
Primarily Uses
RMXP
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
 

TheoAllen

Self-proclaimed jack of all trades
Veteran
Joined
Mar 16, 2012
Messages
5,592
Reaction score
6,522
First Language
Indonesian
Primarily Uses
RMVXA
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

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.
Some of the images are disposed. Look at how draw_face at the Window_Base

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.
 

nio kasgami

VampCat
Veteran
Joined
May 21, 2013
Messages
8,949
Reaction score
3,042
First Language
French
Primarily Uses
RMMV
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.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
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 is 

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
 
Last edited by a moderator:

Tsukihime

Veteran
Veteran
Joined
Jun 30, 2012
Messages
8,564
Reaction score
3,846
First Language
English
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).
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.

My assumption is that raw bitmaps are being stored in memory.

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.
Where is the cache clear being called? I did a search and didn't see anything.

Unless the `clear` method is special and is called automatically or something.

The cache doesn't seem to automatically dispose things either

Code:
def self.include?(key)  @cache[key] && !@cache[key].disposed?end
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?
 
Last edited by a moderator:

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.
Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD
How many parameters is 'too many'??

Forum statistics

Threads
105,862
Messages
1,017,049
Members
137,570
Latest member
fgfhdfg
Top