sharpdx / SharpDX

SharpDX GitHub Repository
http://sharpdx.org
MIT License
1.69k stars 640 forks source link

[X3DAudio] Memory leaks in SharpDX.X3DAudio.Emitter.__MarshalTo #393

Closed OndrejPetrzilka closed 10 years ago

OndrejPetrzilka commented 10 years ago

internal unsafe void MarshalTo(ref Emitter.Native @ref) makes allocations using Marshal.AllocHGlobal, but this memory is never released, not even in __MarshalFree

It occurs when calling X3DAudio.Calculate and any curve (VolumeCurve, LFECurve or other) is set on Emitter

ArtiomCiumac commented 10 years ago

From what I see in the code - freeing the memory was intentionally commented out. Can you please post a sample project that reproduces the issue so I can debug and fix it?

filoe commented 10 years ago

As far as I can see the out commented code calls FreeHGlobal twice for VolumeCurvePointer.

xoofx commented 10 years ago

As far as I can see the out commented code calls FreeHGlobal twice for VolumeCurvePointer.

Good catch! That explains the comment about double deallocation...

ArtiomCiumac commented 10 years ago

Sorry for late response, the commit above should fix the issue. Please let me know if this helps.

OndrejPetrzilka commented 10 years ago

We have rewritten the code to use custom-made wrapper, because issue was critical. We won't be probably going to rewrite it back.

xoofx commented 10 years ago

We won't be probably going to rewrite it back.

Not sure to understand your comment? What do you need to rewrite?

OndrejPetrzilka commented 10 years ago

When memory leak was found, it was critical issue, so PInvoke wrapper was made for X3DAudio. Whole engine now uses SharpDX except X3DAudio.

We won't replace this PInvoke wrapper anytime soon, because it would require additional testing etc...so I cannot really test the fix. Btw, it's game 'Space Engineers'.

xoofx commented 10 years ago

oh, no problem. Yep, I know your project. ;)