
TextPrinter leaks
Posted Thursday, 3 June, 2010 - 08:40 by entity| Project: | The Open Toolkit library |
| Version: | 1.0.0-rc1 |
| Component: | Code |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | by design |
Jump to:
Description
I know that TextPrinter is deprecated, but I need it in my application.
Unfortunately the TextPrinter seems to leak with dynamic updated strings.
As a example: The allocated memory of the following example grows with ca. 2MB/s:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using OpenTK.Graphics.OpenGL; namespace WindowsFormsApplication1 { public partial class Form1 : Form { private OpenTK.Graphics.TextPrinter printer = new OpenTK.Graphics.TextPrinter( OpenTK.Graphics.TextQuality.Default); private Font font = new Font(FontFamily.GenericSansSerif, 12); private int cnt = 0; public Form1() { InitializeComponent(); Application.Idle += new EventHandler(Application_Idle); } void Application_Idle(object sender, EventArgs e) { glControl1.Invalidate(); } private void glControl1_Paint(object sender, PaintEventArgs e) { GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); GL.MatrixMode(MatrixMode.Modelview); GL.LoadIdentity(); printer.Begin(); printer.Print((cnt++).ToString(), font, Color.Azure); printer.End(); } private void glControl1_Load(object sender, EventArgs e) { int w = glControl1.Width; int h = glControl1.Height; GL.MatrixMode(MatrixMode.Projection); GL.LoadIdentity(); GL.Ortho(0, w, 0, h, -1, 1); GL.Viewport(0, 0, w, h); } } }


Comments
#1
The TextPrinter is not deprecated, it's simply unmaintained. Does the GC not kick in to reclaim memory after a while?
Edit: you need to specify
TextPrinterOptions.Dynamic* when printing dynamic strings, otherwise you will get a memory leak.(*) It's been a while, so this might be named differently. It's the last parameter for TextPrinter.Print(), IIRC.
#2
Thank you! No leaks when calling TextPrinter.Print() with
OpenTK.Graphics.TextPrinterOptions.NoCache#3
Closing the issue.
#4
Since TextPrinter class is in OpenTK.Compatibility.dll in OpenTK 1.0, and if add OpenTK.Compatibility.dll to reference in a project, it will cause namespace conflict problem, what is solution to overcame the compiling problem?
#5
Your question isn't really relevant to this issue, so it would be best to post it on a new forum thread.
#6
Agree. Sorry about that.