daleluck's picture

Memory Usage Constantly Rising

Project:The Open Toolkit library
Category:bug report
Status:closed (invalid)

I was in the middle of my other project and noticed the large amount of memory that my program had taken up. Since it was just a test, I decided I'd start again and just port over the pathfinding library whilst redesigning exactly how the system works - but then I noticed that the memory allocation of the program starts at 17000k and constantly rises as the program runs, even with just the below piece of code.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using OpenTK;
using OpenTK.Input;
using OpenTK.Graphics;
using OpenTK.Graphics.OpenGL;
namespace Program
    class Program
        // Game Window Details
        public static GameWindow MainGame;
        public static int WindowWidth = 800, WindowHeight = 600;
        public static double WindowFPS = 30.0;
        static void Main(string[] args)
            // sets up the window for 2D, disallowing manually resizing it
            MainGame = new GameWindow(WindowWidth, WindowHeight, GraphicsMode.Default, "Test Window");
            MainGame.WindowBorder = WindowBorder.Fixed;
            GL.Ortho(0, WindowWidth, WindowHeight, 0, 0, 5);
            // sets up the different functions
            MainGame.RenderFrame += OnRenderFrame;
            // runs the window at 60.0fps
        static void OnRenderFrame(object sender, FrameEventArgs e)

All it does is clear the background to be black, but the memory it takes up is constantly rising - there's nothing else to the program, just setting up the window and then making the background black. I really want to know why this is happening and how can sort it out.


Comment viewing options

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


Be sure to also test a release build with no debugger attached.
I don't have the time to test it out myself atm. But I would be interested in the results.

Also I think that when the memory reaches 1mb the garbage collector might clean up the 'leaks'
But as I said, I haven't tested it yet :-)

daleluck's picture


Tested it in the release build, same problem arises. Also, what do you mean by it cleaning up once a megabyte of memory was reached? As far as I know, the amount of memory stands for how many kilobytes the program is using, and with this program starting off at 16000k memory usage I left it for a bit and checked back and it had risen to 25000k with no signs of slowing down or removing memory.

I also tested it with the 'quick start' sample and found the exact same issue, so I'm fairly sure it's not something I've written doing something wrong. I never noticed this before because I never opened my program for prolonged amounts of time, but since I'm making a game where the expectation is the user WILL have it open for so long it's kind of an issue I need sorting out quickly.

Snorkel's picture


What I meant was that maybe the program is generating garbage.
And if I remember correcly the garabage collector only starts collecting once 1mb of memory is allocated ( I could be wrong here ).

So if its garabage it's not really a leak, just lazy cleanup by GC.
But this might still be problem depending on how much garbage is generated each frame, ideally it shoudn't generate any.

daleluck's picture


I'm not sure how I'd go about lowering the amount of garbage that it makes. It happens in the example project too, so I'm sure I've not done anything wrong. I'll carry on with writing the program and get around to the memory cleanup once a solution has arisen, or hopefully, as you've suggested might happen, the program will just sort itself out at some point.

puklaus's picture


Cant confirm. This code (net) takes 35MB memory but it didnt go up.

daleluck's picture


Well that's odd, that code with nothing else attached uses up just over 15000k when it's executed and then steadily rises every few seconds (odd that it isn't doing it every couple of frames) with mine. I'm not sure what to do about this now if it's just a problem that I'm having.

the Fiddler's picture


Status:need info» closed (invalid)

I cannot reproduce this on Windows, Linux or Mac OS X using the native or the SDL2 backend. This may be a driver issue.

If you can still reproduce this using OpenTK 1.1 beta4, please file a bug report at https://github.com/opentk/opentk/issues

Make sure to include the following information:

  • Operating system
  • GPU type and driver