Avon's picture

Keyboard input and memory use

Hello! I'm a rookie to C# and OpenGL but so far the documentation has solved all my issues, great work OpenTK!

My question is in regards to memory use and keyboard input. I monitor memory use though Task Manager, I expect this is a really lame method but it works for me and I can see the memory use reflecting what I've coded so I am happy.

FYI: I use Visual C# 2010 Express, on a Win7 x64 machine, and I'm using the OpenTK DLL 1.1.804.3121 that I got from the "opentk-2012-03-15.zip" in the Nightly Builds list.

Anyone can recreate this by creating a new console application solution and inserting the code from Game.cs in the Source\Quickstart directory distributed with OpenTK. Happens in Debug and Release.

When I first run the application memory use climbs at about 4kb/sec until it stops after about 3mb. This is fine I expect there is a good reason, even if I don't understand it.

So after a few minutes with my application now idle and memory not changing I press and hold a key on my keyboard, lets say the letter Q. There is NO code to do anything when Q is pressed, however based on my understanding the KeyboardDevice created by GameWindow will be reacting in some way to the event of Q being pushed. I accept this, however my memory use increases by 4kb/second when a key is held down. If I hold down multiple keys it's still only 4kb/s.

Also in my own game-in-progress with a lot more happening in the update and draw loop memory increases by much more, close to 7kb/s, when pushing a key that isn't coded to do anything.

So is this normal? Should I be concerned? I'm asking because in many games at least 1 key is held down all the time, and over a few hours of play this is a lot of extra memory use!

-Avon


Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Robmaister's picture

The way the garbage collector works is that it keeps allocating for a while then collects objects that no longer have any references to them. The timing of the collection isn't predictable, but it's still observable:

http://www.dotnetperls.com/garbage-collection

Also, make sure that you're pulling memory used from GC.GetTotalMemory(false). If you're pulling it from the system, it'll get the total amount of memory that the CLR allocated for your application's heap.