سؤال

I have a schedule system that generates games into a certain schedule that could be a 1000 games or more. During this alot of processing occurs and object creation. When I run this auto schedule feature my memory footprint for this website goes up significantly. The objects created are plain poco objects and I am using Entity Framework to grab certain data before the scheduling occurs.

My question is how do I make my memory footprint disappear after all this object creation? Do I need to add IDisposable to all these poco classes so they are removed right away?

Update

Found the issue, NLOG was turned on debug and I had a ton of debug statements going on, which in my case kept increasing the memory! So I turned it to debug!

هل كانت مفيدة؟

المحلول

Do I need to add IDisposable to all these poco classes so they are removed right away?

Anything that implements IDisposable should have IDisposable.Dispose() called as soon as the object is no longer needed. Typically the best way do accomplish that is with a using statement.

IDisposable is there to allow for expensive resources (think DB connections) and/or unmanaged resources (think a COM handle) to be released as soon as the object no longer needs access to them. Calling IDisposable.Dispose() will release those resources, but will not cause the managed object to be garbage collected any sooner.

My question is how do I make my memory footprint disappear

The .NET runtime will garbage collect when it things it is the appropriate time to do so. Although you can force garbage collection, the runtime will almost always make a better decision on timing than you would.

What might cause the Garbage Collector to be unable to release memory?

If you still have a reference to the objects somewhere, they will not be garbage collected. You can use the memory profiler in Visual Studio to see what is still referenced (therefore uncollectable) after your schedule job runs.

Should you be worried?

Probably not. Even though the .NET Runtime may allocate significant memory, it will usually release it in a very efficient manner if the memory pressure on the system so warrants. Just be sure you are not holding object references longer than needed.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top