I have been using WPF for a few years now and don’t have any experience with anything but managed code. I started writing an app that uses a lot of win32 interop and i started wondering if i was leaking memory or generally doing something stupid that i didn’t know about… So i thought i would seek some advice!
Is there any gotchas/tips/tricks when using win32 calls inside managed code?
I am mostly interested in memory/garbage collection but any other tips are welcome!
There are no gotchas. You free all resources that you allocate (unless the documentation indicates that the call you make takes over the resource, relieving you from ownership), and that’s all there is to it. GC doesn’t enter into it at all.
As a tip,
System.Runtime.InteropServices.SafeHandleis a stock helper class to use Win32 handles RAII-style.