views:

166

answers:

1

I'm trying to track down a memory leak and I think it has to do with the custom cursor images being used. A new cursor seems to get created and displayed every time a certain object is dragged around on the form, but I can not find anywhere it is being disposed.

I've read that it needs to be destroyed, but I'm not sure how to go about that. Shouldn't it automatically be disposed when the cursor is changed?

+3  A: 

Never assume anything is going to be automatic. =)

Here is some code I use, hopefully it is what you are looking for. I just picked out the jist of it, if you need more detail let me know.

    [DllImport("user32.dll")]
    private static extern bool DestroyIcon(IntPtr handle);
    private Cursor moveCursor;

    private void DestroyCursor()
    {
        if (this.moveCursor != null)
        {
            DestroyIcon(this.moveCursor.Handle);
        }
    }
Dustin Brooks
Well, I'm not sure it fixed the memory leak issue I'm having, but the cursors may not be the issue. This appears to be working though :)
Shaun L