..or make it null
does not have the same effect than Dispose()
!
Be careful. You only should dispose your object. Set to null
is not required
And set to null
does not immediate free any resources.
- Use GC.Collect() if required.
Normally this is not required, because the GC has his own lifecycle when to collect. Since .NET 4.5 you can compact the LOH, if you think there is a fragmentation:
GCSettings.LargeObjectHeapCompactionMode = GCLargeObjectHeapCompactionMode.CompactOnce;
GC.Collect();