Memory leak in BindingBase.MarshalStringArrayToPtr #144

nitroxis opened this Issue Jun 22, 2014 · 3 comments


None yet
4 participants

I'm using GL.GetUniformIndices a lot and noticed that my program was allocating around 2 MB per second and never releasing it. It turned out BindingBase.MarshalStringArrayToPtr was allocating memory which is apparently not released correctly.

Simple code to reproduce this issue:

public static void Main(string[] args)
    int[] index = {0};
    string[] name = {"test"};
    GameWindow window = new GameWindow();
    while (true)
        GL.GetUniformIndices(0, 1, name, index);

I set breakpoints at MarshalStringArrayToPtr and FreeStringArrayPtr, but the latter is never called.

I could successfully reproduce the problem with the provided code.


Frassle commented Jun 22, 2014

The call to FreeStringArrayPtr is never emitted by Rewrite. I assumed this was the case the other day when I was redoing the bindings (with a new rewriter that does call FreeStringArrayPtr) and I kept getting access violations when calling FreeStringArrayPtr (this is now fixed, see 22760a4). Given that calling the method pretty much guarantees an AV it must of never been called before or someone would of noticed.

thefiddler added this to the 1.1.4 milestone Jun 23, 2014

@thefiddler thefiddler added a commit that referenced this issue Jul 7, 2014

@thefiddler thefiddler [Rewrite] Refactored string prologue/epilogues
We currently have three categories of string parameters: `string`,
`string[]` and `StringBuilder`. (OpenTK 1.2 adds one more: `ref
string`.) Each category needs to be marshaled separately into a native
character array.

This commit implements the following changes:
- string[] epilogues are now correctly emitted, instead of being
- string[] prologues and epilogues now use the same local variable name.
- all epilogues are now generated with a single pass over the function
parameters, instead of requiring a separate pass for each category.
- string prologues and epilogues now allocate local variables based on
the relevant parameter *name* rather than the parameter *type*.

Fixes issue #144.

thefiddler commented Jul 7, 2014

Thanks for the bug report, fixed via #147

thefiddler closed this Jul 7, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment