I've got a crawler application (with C#) that downloads pages from web . The applying take more virtual memory , even i dispose every object as well as use GC.Collect() .

This , have 10 thread and every thread includes a socket that downloads pages . In every thread , i've got a byte[] buffer that store content of page , and also have an string str_content which i store inside it , content of page in string . I've got a Sytem.Timer that each 3 second chech , if each thread continues to be stopped , assign it new thread and begin it.

I personally use dispose method as well as use GC.Collect() during my application , however in 3 hour my application take 500 Megabytes on virtual memory (500 Megabytes on private bytes in Process explorer) . Then my system is going to be hang and that i should restart my pc .

  1. will it be rude , Basically assign my byte[] and string to null ?

  2. Can there be in whatever way which i use to free virtual memory ?

Thanks .

To begin with, you Should not be calling gc.collect() anyway, because it is a pricey call, and should not be necessary.

If you're seeing growth And you're simply still calling gc.collect() you've assets that also have references, thus they cannot be collected.

I'd start searching at the code and ensuring all your objects are declared in the proper scope, that you're while using Using Statement syntax to make sure that products applying IDisposable are correctly cleared up and perform a full overview of your code.

The next phase is always to have a tool like Bugs profiler or even the like and check out what's really saved in memory.

It might take search for your code to determine where your memory leaks are. It's likely in occasions that you are tying into (either by hand or instantly) that create apparently-out-of-scope objects not receiving correctly disposed.

In C# (as well as in Java) as lengthy as you've a mention of object, this program atmosphere assumes you're still while using object. Calls to free memory is only going to free unused objects. The bottom line is to prevent while using object.

Chances are excellent you've something similar to:

Object mine = new Object();

the bottom line is that you simply likewise need something similar to:

mine = null;

to signal the "mine" object is no more getting used. Typically these complaints don't take place in code blocks such as this because when you leave the block, the variables aren't accessible any longer:

public void process() {
  Object mine = new Object();

Typically these complaints take place in code blocks such as this, since the Collection builds up objects with time:

static List tasks = new ArrayList();

public void process(String item) {

The bottom line is that with no corresponding tasks.remove(item) their email list holds references towards the products forever thwarting garbage collection efforts.