This project is read-only.

Massive memory leaks in WPF version

Dec 4, 2011 at 11:54 AM
Edited Dec 4, 2011 at 11:55 AM


My WPF application tries to use SharpGL... but after a few seconds of semi-smooth rendering of a spinning model the app crashes with a OutOfMemory exception..

Is this a known issue?

A link showing the exception in Visual Studio:

Dec 5, 2011 at 7:04 AM

In the earlier versions of SharpGL this was a problem - have you tried using the latest cut of the code? I will not be able to look into this issue properly until Jan as I'm on holiday and have very limited internet access, however if you post any details that may be useful I will look into it then

Dec 5, 2011 at 4:25 PM
Edited Dec 5, 2011 at 4:27 PM

Well, I have just downloaded the latest (I think) binaries - SharpGL 2.0 Beta 1.

All I do is launch the app, and after a few seconds, the app crashes. Some parts of my code:




<gl:OpenGLControl Name="GLPanel" DockPanel.Dock="Left" Width="Auto" HorizontalAlignment="Stretch"
Resized="OpenGLResized" />

The GL code:

private float hangle;
private float vangle;
private float hspeed = 0.1f;
private float vspeed = 0.0f;

public void handleResize(OpenGLEventArgs args)
OpenGL gl = args.OpenGL;


(float)gl.RenderContextProvider.Width / (float)gl.RenderContextProvider.Height,
1.0f, 300.0f);
gl.Translate(-50, -50, -125);

public void handleInit(OpenGLEventArgs args)
public void handleRender(OpenGLEventArgs args)
if (File == null || File.Faces == null)

OpenGL gl = args.OpenGL;

hangle += hspeed;
vangle += vspeed;
if (hangle >= 360) hangle = 0;
if (vangle >= 360) vangle = 0;


gl.Translate(50, 50, -50);
gl.Rotate(vangle, 1, 0, 0);
gl.Rotate(hangle, 0, 1, 0);
gl.Translate(-50, -50, 50);


for (int i = 0; i < File.Faces.Count; i++)
myApp.Vertex color = File.Colors.ElementAt(i);
gl.Color(color.x, color.y, color.z);

float[] v1 = File.Faces.ElementAt(i).V1;
float[] v2 = File.Faces.ElementAt(i).V2;
float[] v3 = File.Faces.ElementAt(i).V3;

gl.Vertex(v1[0], v1[1], v1[2]);
gl.Vertex(v2[0], v2[1], v2[2]);
gl.Vertex(v3[0], v3[1], v3[2]);




Dec 6, 2011 at 8:46 AM

im not sure but i think he was refering to  the latest source in the SVN have you tried that

look under source code and downloadthe last update if you still have the same issue post back.

Dec 6, 2011 at 4:18 PM

I've just tried the 7099 changeset version, still the same issue :-( The app crashes after few seconds rotating only about 200 triangles

Dec 11, 2011 at 11:50 AM
Edited Dec 11, 2011 at 11:51 AM

no chances of looking into this bug? :( Maybe a workaround then?

Dec 14, 2011 at 4:32 AM
Edited Dec 14, 2011 at 5:29 AM

I get the exact same issue with the latest binaries. I only put the control under a wpf window without any code behind. Within a  couple of seconds the memory raise up to 1000MB.

Edit1: I at least found the source of the issue:

In the function (In SharpGL.WPF)

void timer_Tick(object sender, EventArgs e)

FormatConvertedBitmap  are created at an insane rate and the garbage collector is just not fast enough the remove them from memory. That explain why I'm jumping from 300MB to 1000MB then back to 300MB.

I'll try to find and alternative way to complete this task. I'll let you know if I find something.

Edit2: Ok I found a work around it is not pretty but it works perfectly

Just add GC.Collect(); at the beginning of the void timer_Tick function like this:

void timer_Tick(object sender, EventArgs e)



Let me know if it solves your issue or not



Dec 14, 2011 at 7:39 AM

yes, it works ;-)


now my app memory is hardly at 80M .. not 1G like before :-)

Jan 17, 2012 at 2:47 PM

Guys - good work on this, I'm just checking it in as a fix now, it will be in the codebase shortly.

Jan 17, 2012 at 2:48 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.