Let’s say we are developing a game with monsters in it. And we create a MonsterHandeler class which loads all the bitmaps that our monster’s gonna use. We then store these bitmaps in variables. Then we create a Monster class which ALSO stores Bitmap variables sent into the constructor from the MonsterHandeler class. If we then have 10 monster objects on the screen would these variables share the memory or take up its own place?
I hope I wasn’t to unclear about what I meant, and thanks in advance.
The bitmaps are being passed as references, and probably not copied (unless you’re copying them). Your ten monster objects will occupy some memory, of course, but if your bitmaps were already loaded, there won’t be any additional penalty for storing their references in the monster objects.
Note that if the original references to your bitmaps are dropped, the references to them being held in the monster objects would keep them from being freed, but that’s what you probably want.