Author Topic: Memory  (Read 2312 times)

v6v

  • Clever
  • Fanatic
  • ***
  • Posts: 500
  • Has renamed his project to Galaxy!
    • View Profile
    • My Developer Page!
    • Email
Memory
« on: 2012-03-10, 06:34:46 PM »
Hello. When running my game, I seem to spike about 40,000 K each time I load a new map- even if I unload the current. Is there a simple solution for this? The only thing that I can see that makes it spike is the transition effect used- which is drawing 8 256x1280 horizontal bars across the screen. I thought that if I unloaded the current map, that the rest would follow... is there a way to fix this? I don't understand memory management (or micro-optimization, which led me to a failed attempt at a game on another platform)


Thank you.

~#Sharp

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Re: Memory
« Reply #1 on: 2012-03-11, 02:58:05 PM »
.NET Framework does its own memory management, and, as I understand it, often times won't give up memory until there's some real pressure/reason to clean up.  This is for performance reasons.  You might be able to force it to clean up memory with GC.Collect.

v6v

  • Clever
  • Fanatic
  • ***
  • Posts: 500
  • Has renamed his project to Galaxy!
    • View Profile
    • My Developer Page!
    • Email
Re: Memory
« Reply #2 on: 2012-03-12, 07:21:02 PM »
Running the Collector for one frame seemed to allay the issue. It still seems large however and is ever increasing. I'm looking into alternatives at the moment.


v6v

  • Clever
  • Fanatic
  • ***
  • Posts: 500
  • Has renamed his project to Galaxy!
    • View Profile
    • My Developer Page!
    • Email
Re: Memory
« Reply #3 on: 2012-03-26, 09:28:25 PM »
It appeared to be my OGL calls. Since I left an increasing amount of garbage each frame, mainly from drawing 2 spheres each frame in immediate mode, and the GC didn't have time to dispose what I had used faster than it was made,

System.Threading.Thread.Sleep(0);

This does the trick. It gives the GC enough time to breathe. I've stabilized the Mem to an even 137,000, which, mind you, isn't entirely impressive, compared to other games I play which are a clean 40,000 to 45,000, it's much better than a 200,000 game (Hey, even look at Minecraft- but I haven't played that or updated it in 3 months). Especially since I have so much needing to be drawn in Immediate Mode, and Lidgren.Network doesn't seem to have much of an effect on the Private Working Set of memory.

The game had even crashed my PC about three times before. Things became slow, I checked the processes- about 2,400,000 K :O and for some reason the Apache Handler on my computer had said "The process completed successfully" and I had an unreadable memory error. Before, it happened with Google Chrome (The flash player was unstable) but I'm really hoping the game can 'play nice' around other processes without 'ruining it for everybody'