Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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.

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

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.

share|improve this answer
    
Thank you for the answer, it helped a lot! (I would up vote if I could :P) –  Rasmus Appelkvist Dec 4 '12 at 3:12
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.