Quantcast
Channel: Community | MonoGame - Latest topics
Viewing all articles
Browse latest Browse all 6821

Strange memory behaviour

$
0
0

@Qbjik wrote:

Hello!
While working on content management, I noticed that my loaded from stream textures are making the game use a lot of memory. It made me quite surprised because I made dynamical loading/unloading and meanwhile my old project with plain dictionary full of textures was using like 5 times less or so.
So I started testing around and got into situation where loading texture into my ContentManager class is better than executing same code in main game class.
Example of loading from main class:
_items = new Dictionary<Item, TextureAtlas>();
(...)
_contentManager.LoadContent(_texturePackName); // this method executes same code as line below
_items.Add(Item.Gem_blue, TextureAtlas.Create("BlueGem", loadTextureFromFile("Content/giant_white_nothing.png"), 7444, 3264));
(...)
private Texture2D loadTextureFromFile(string path) {
FileStream fileStream = new FileStream(path, FileMode.Open);
Texture2D sprite = Texture2D.FromStream(GameMain.Instance.GraphicsDevice, fileStream);
fileStream.Dispose();
return sprite;
}

The _contentManager.LoadContent method is pretty much the same. There is nothing that would change anything in the way textures are stored or loaded, just lots of other stuff that gets loaded as well.
Differences are like this:
Not loaded at all: 120MB
Loaded from manager: 260MB
Loaded from main: 475MB
And I'm really out of ideas what could be the reason.

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 6821

Trending Articles