Question: I have a list called `Population`, is a great list of very many positions and at some point I stop using it. How I can free the resources?
Then this is part of the code:

```
 private List <BasePopulation> Population=new List <BasePopulation>();
 Population.SomeMethod();
 Population.Clear();

```

I used the Clear method, but not works. Any idea?

Answer: 
Well, since the garbage collector (GC) is taking care of the memory management for you, the first thing you can do is getting rid of all references to the list (and the contained elements) so that the GC is able to remove it on the next occasion. You can do this, for example, by explicitly setting

```
Population = null;

```

If this isn't enough for you, for example because you're **really** eager to get rid of the objects **now** *and* you can accept non-optimal run-time behaviour, you can tell the GC to start collecting objects **now** via

```
GC.Collect();

```

More information about this method can be found [here](https://msdn.microsoft.com/en-gb/library/xe0c2357(v=vs.110).aspx).

As indicated above, this practice can induce a performance penalty since it forces the GC to clean up resources at a point in the program where it usually wouldn't. Directly calling the method is thus often discouraged, but it might serve your needs if this is really a special point in your application. As a practical example, I've successfully improved peak memory usage in a program that requires **a lot** of objects during an initialization that can be discarded once the actual program execution has started. Here, the small performance penalty for calling `GC.Collect()` after the initialization was justifiable.
You must clear the list, and after that invoke the GC to remove it from memory. As follows with extensive method:

```
public static void ClearMemory<T>(this List<T> lista)
{
    int identificador = GC.GetGeneration(lista);
    lista.Clear();
    GC.Collect(identificador, GCCollectionMode.Forced);
}

```