Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Question about bitmap.dispose

  When we create a sprite like this

Code:
  @object = Sprite.new
  @object.bitmap = Bitmap.new(some_width,some_height)

when dispose, should I just do this
Code:
  @object.dispose

or this
Code:
  @object.bitmap.dispose
  @object.dispose

I mean, would the bitmap be freed if the sprite's freed? In the animation system that I use, if I don't free the bitmap, it'll keep on eating up the memory. But in the shooting game that I'm working on, I don't have to free the bitmap and the memory is still the same, so it confuses me :(

Thanks you in advance ^ ^
 
That's what I thought too. But I still want to know as for the reason why. And when I do that in my shooting game, all the bullets bitmap are gone, not the only one that is out of screen. But when I use only self.dispose, only the sprite is gone and the memory is still the same. = =
 
Both are different objects, and each of them must be disposed separatedly, as in the Sprite implementation it does not dispose the bitmaps it´s holding. If it was that way, RPG::Cache would never be possible :D Also, Sprites consumes way much less memory than bitmaps. That´s why you see that the memory consume of the game doesn´t drop much after you dispose it. Think of it as a single bitmap object is reutilized in several sprites, and therefore saving memory by not needing a single bitmap for each sprite to show the same thing on the screen

I say, if you load a bitmap through the cache, don´t dispose it unless you have a good reason lol, and try not to load lots of bitmaps at once too, it´ll run your computer out of memory if you abuse :D
 
Thanks Linkin_T!  I get it now. After reading your post and go back to the manual, I realize it's also written in the manual about Rpg::Cahce.  Should have read it more carefully  orz
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top