That is not a trick to save the bitmap to cache. The bitmap is already saved in the cache the first time it's loaded (Cache.animation). What you're doing is just not manually disposing of the bitmaps. Since you make the variable point to nil, the bitmap is lost to you anyway - you lose the handle to it, and it's not going to be reloaded next time you need it - it will be loaded from Cache.animation just as it always is. So while the end result may be something along the lines of what you're seeking, you're not achieving it by saving the bitmap to cache.
If you were going to do the above, you may as well comment out those entire two blocks. No point in reducing something then checking its value if you're not going to do anything afterwards.
If you're not disposing it, but still setting it to nil at the end of that method, either the GC is going to dispose of it anyway, or your memory usage is going to gradually increase the longer you play the game (especially as you see more and more animations played). I don't think either is a very good practice.
There you go then 🙂 I thought Cache.animation gave a copy.
Yeah, I knew it. Just because I removed the dispose function, then I said the bitmap was saved in Cache. We don't need to reload same file using Bitmap.new. Because it's so time consuming for large image. Since the concept of Cache itself is to store data in order to faster access (Both RGSS3 and our computer).
I would like to hear another opinion if there's any 🙂
Oh, that's makes sense. I didn't think of the hue changed bitmap. So basically, if I remove the dispose function, the image with same filename will be stored in different bitmap object depends on the variation of its hue which may take our memory usage more. But, I don't want to my game causes more lag either :/
An animation bitmap would be around 1 - 5mb in ram (I tried with Attack11 animation, it would be around 4mb). So if you have around 1 - 2gb ram, this wouldn't be a big matter, except you use too many big animations and/or hue change them.
Anyway, you can try these if you want a better performance:
1, Dispose the animation(s) that is not used recently (for example, for hue change cache, you have a maximum bitmap number is around 50, when a new bitmap created, dispose the bitmap at the beginning of cache hash).
2, Cache most used animations, dispose all other ones.
Doesn't that defeat the purpose caching?
Without knowing anything about how memory works, I would assume that if something is "cached" in the program memory, then you would expect the memory used to be higher than if it's not being cached.
I'm not sure how disabling the dispose is a trick to cache the animation.