My program seems to generate a lot of garbage then it calls an unmanaged dll function which allocates a lot of memory (~500+MB). The unmanaged function usually fails with an out of memory error. However if I call GC.Collect just before calling the unmanaged function, it never fails.
Task Manager shows the memory use climb monotonically then drop dramatically at the GC.Collect call. Without that call, it continues climbing till it fails.
Everything I read says "don't use GC.Collect except special cases". Could this be such a case? The only problem with calling GC.Collect seems to be that it might be slow. I don't care if it's slow so does that mean it's harmless?