I'm fairly new to programming, and I've pretty much learned all the things I know on the go, while working on projects. The problem is that there some things that I just don't know where to begin searching.

My question is about performance, and how can multiple instances of the same object affect it -- Specifically, I'm talking about XNA's "GraphicsDevice" class. I have it instanced on four different parts of my game, and in three of those, the object has the exact same values for all the attributes. So, in that case, should I be using the same instance of GraphicsDevice, passing it as a parameter, even if I use it in different classes?

I apologize if the question seems redundant, but like I said, I've taught myself most of what I know, so there are quite a few "holes" in my learning process.

  • 1
    \$\begingroup\$ For your reference and just to be clear, "objects" are instances of a class. You don't have "instances of objects." You may have a reference to the same object in memory, but otherwise, "objects" are instances of a class (in your case GraphicsDevices). You may want to clarify if those "other instances of the same object" are really references to the same object or are separate objects. Do you call new GraphicsDevice(...) anywhere? \$\endgroup\$ Jul 23, 2012 at 18:39
  • \$\begingroup\$ To clarify terminology: classes are types, objects/instances are variables. \$\endgroup\$
    – 3Dave
    Aug 22, 2012 at 20:18

1 Answer 1


Yes, you should have only one GraphicsDevice per game, and don't instance it manually ever. Just pass it as a parameter to the functions that need to access it or share it via a global singleton class.

  • \$\begingroup\$ Thank you for the reply! In your answer, you said that I shouldn't "manually instance" it. What do you mean by that? \$\endgroup\$
    – lggmonclar
    Jun 23, 2012 at 18:39
  • 2
    \$\begingroup\$ He means never call new GraphicsDevice(). This line should not appear in your code. XNA handles this for you and provides you with the only GraphicsDevice instance you will need. \$\endgroup\$
    – A-Type
    Jun 25, 2012 at 17:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .