A
A
Adolf Milos2019-04-02 18:18:32
Algorithms
Adolf Milos, 2019-04-02 18:18:32

How to clear memory occupied by C# list?

There is a list of strings List (), I add a lot of elements to it. How to free memory from the list when I don't need it? Please write a command, thanks

Answer the question

In order to leave comments, you need to log in

2 answer(s)
G
GavriKos, 2019-04-02
@GavriKos

Remove all references to it, and then do GC.Collect

I
Ivan Filatov, 2019-04-02
@NYMEZIDE

In theory, you should not bother with the garbage collector.
He himself knows when to check if there are unused objects and will clean them up himself.
If you call it often, in particular GC.Collect, it will slow down your application.
And yet, if you have 20 million lines, then it's better to use IEnumerable and work with a limited number of lines - page by page, for example. Then there will be no problems with memory.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question