Please look at this code:
Code: Select all
/// <summary>
/// Pinned pointer wrapper. Created in this way to alow 'using' semantics.
/// </summary>
public sealed class PinnedPointer : IDisposable
{
public IntPtr Pointer;
GCHandle _handle;
public PinnedPointer(byte[] Data)
{
_handle = GCHandle.Alloc(Data, GCHandleType.Pinned);
Pointer = _handle.AddrOfPinnedObject();
}
public PinnedPointer(IntPtr Data)
{
Pointer = Data;
}
public void Dispose()
{
if (_handle.IsAllocated)
{
_handle.Free();
}
}
}
I am using it with 'using' semantics...
Code: Select all
using (PinnedPointer p = encodingData.PinnedOriginal)
{
SaveBitmap(encodingData.Stamp, p.Pointer);
}
However, when I start the app and YourKit is running with memory profiling (even memory allocation trace isn't on!!!) memory starts to skyrocket, and in few seconds app is finished (since it allocates video frames that are large, it consumes the memory rather quickly).
Do you have an idea what is going on - since I need YourKit to be able to profile exactly this app first.
Thank you, any pointers (fixed or otherwise) would be appriciated