Pinning data messes up YourKit

Questions about YourKit .NET Profiler
Post Reply
mosmondor
Posts: 1
Joined: Wed Sep 14, 2011 9:39 pm

Pinning data messes up YourKit

Post by mosmondor »

Hi there!

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();
            }
        }
    }
That's my helper class.

I am using it with 'using' semantics...

Code: Select all

                using (PinnedPointer p = encodingData.PinnedOriginal)
                {
                    SaveBitmap(encodingData.Stamp, p.Pointer);
                }
and it works FINE, because it was something refactored from before, and the functionality is intact.

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 :)
Anton Katilin
Posts: 6172
Joined: Wed Aug 11, 2004 8:37 am

Re: Pinning data messes up YourKit

Post by Anton Katilin »

Hello,

We cannot reporduce the problem.

Do you have an isolated code snippet which uses PinnedPointer and exposes the problem?

Best regards,
Anton
Post Reply