• Advertisement
Sign in to follow this  

[.net] How to disable Automatic Garbage Collection in .NET 1.1 SP1

This topic is 4575 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, I've recently been using only .NET 1.1 (SP0) and handled the Memory myself via a script I wrote - which works very effectively. However when I upgraded to SP1 I noticed Garbage Collections were just taking place randomly with no warning, at first I thought I must of edited my script and made a mistake, then realised SP1 has some type of Automatic Collection. Is there anyway I can turn this off - As it's a nightmare as it's just completely random and unpredictable, and I need to GC.Collect at certain intervals to maintain stability of my application. Any help would be greatly appreciated!

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by infra001
However when I upgraded to SP1 I noticed Garbage Collections were just taking place randomly with no warning, at first I thought I must of edited my script and made a mistake, then realised SP1 has some type of Automatic Collection.

Is there anyway I can turn this off - As it's a nightmare as it's just completely random and unpredictable, and I need to GC.Collect at certain intervals to maintain stability of my application.

What you describe is probably a bad design.

Garbage collection is supposed to run when your app is otherwise idle, and it should be very fast. You should not need to call GC.Collect manually, even in a game.

There are two main reasons (that I'm aware of) that cause it to run slow.

1) You are doing *lots* of allocations that need to be cleaned up. You should probably use objects that are more persistant.

2) You are not calling .Dispose() on resources that take a lot of time to clean up. You can catch that by using a tool like FxCop and calling .Dispose() on all IDisposable objects.

frob.

Share this post


Link to post
Share on other sites
Well it's a MMORPG Server - so it's not your typical game.
The server runs with about 1.0GB usage constantly on load.. and as actions are performed in the world the server obviously uses memory till the server saves locally to the HDD.

So it has to cleanup about 400MB every collection - which takes about 3 seconds, which is way too long as causes the server to freeze for that time.

My method uses manual collection every 6 hours, which uses a warning gump to let players know it's occurring.

With this automatic system it's completely random and thus there no way to warn the players once it's happing - and they just think it's a lag issue, which obviously it's not.

I can solve this problem just by somehow figuring out how to stop this automatic collection.. is this even possible.. ? - that's all I need to know.

Share this post


Link to post
Share on other sites
Quote:
Original post by infra001
I can solve this problem just by somehow figuring out how to stop this automatic collection.. is this even possible.. ? - that's all I need to know.

I do not believe you can stop garbage collection from ever occuring using the publicly available methods.

You can use GC.KeepAlive to prevent early unloading of unreferenced modules, but that doesn't prevent it from ever running.

You *might* be able to find undocumented methods inside the GC module to prevent it from running, or to interrupt it when it starts. It sounds like a bad solution, though.

I'd seriously consider adjusting your design so that it doesn't have to do a 400MB dump. That's going to cause a problem no matter what language or tool you're using.

frob.

Share this post


Link to post
Share on other sites
I have to agree with where frob is coming from here... there has to be a better way to address this.

I would suggest looking over the way your app is designed and look for opportunities where frequently created transient objects can be pooled (such as "action", "transaction", or "message" type objects), so as to reduce overhead for allocation and finalization/collection.

By drawing these frequently used objects from a pool (and just adding another if all objects in the pool are currently in use), and returning/releasing them for re-use, I'll bet that you can maintain a very steady level of memory usage (once the pool has ramped up to size on startup), and minimize the amount of memory that the garbage collector has to reclaim. (note: This approach should also cut down on fragmentation if you pre-allocate your pools at startup, and possibly save on free-space compacting time as well)

I am happy to be corrected if I am wrong, but I recall reading an interview or a blog or a .plan or something waaaay back where Tim Sweeney of Epic suggesting this approach when using Managed DirectX (and I wouldn't be suprised if it happens behind the scenes in many instances) to stave off hiccups caused by the garbage collector, so the idea must have some merit :)


The other suggestion I have is a little less elegant (and makes me cringe a bit), but is there the possibility that throwing hardware at the problem (more processors or faster processors) would reduce it to an acceptable level? Better hardware is often cheaper than reworking an entire software system, even though its a solution that turns the stomach of a developer who takes any pride in what they do :)

Share this post


Link to post
Share on other sites
Quote:
Original post by infra001
So it has to cleanup about 400MB every collection - which takes about 3 seconds, which is way too long as causes the server to freeze for that time.

Don't blame the collector, your design is obviously to blame. Any attempt to try to circumvent the collection mechanism will only make it worse. Work with it, not against it.

Share this post


Link to post
Share on other sites
Horrible design.

Just take a look at RunUO the C# MMOG server (which is open source btw) and they don't need any of these bad designs that you propose. They actually don't have any noticable slowdowns ever.

Share this post


Link to post
Share on other sites
You might want to look into CLR Profiler, which'll give you a timeline of garbage collections, allocated objects, a call graph, and lots of other goodies that'd be useful in improving performance.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
correct me if im wrong but,
GC just deletes any reserved memory with no refrence to it so just make a linklist to serve as a graveyard for dead objects so they can be manualy deleted at a later time

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement