C# / XNA - Load objects to the memory - how it works?
- by carl
Hello
I'm starting with C# and XNA. In the "Update" method of the "Game" class I have this code:
t = Texture2D.FromFile( [...] ); //t is a 'Texture2D t;'
which loads small image. "Update" method is working like a loop, so this code is called
many times in a second. Now, when I run my game, it takes 95MB of RAM and it goes slowly to about 130MB (due to the code I've posted, without this code it remains at 95MB), then goes immediately to about 100MB (garbare colletion?) and again goes slowly to 130MB, then immediately to 100MB and so on. So my first question:
Can You explain why (how) it works like that?
I've found, that if I change the code to:
t.Dispose()
t = Texture2D.FromFile( [...] );
it works like that: first it takes 95MB and then goes slowly to about 101MB (due to the
code) and remains at this level.
I don't understand why it takes this 6MB (101-95)... ?
I want to make it works like that: load image, release from memory, load image, release from memory and so on, so the program should always takes 95MB (it takes 95MB when image is loaded only once in previous method). Whats instructions should I use?
If it is important, the size of the image is about 10KB.
Thank You!