Garbage collection on one object, C #

I need to get rid of the object so that it can free everything that belongs to it, but it does not implement IDisposable, so I can not use it in the used block. How can I collect the garbage collector?

+3
source share
6 answers

You can force a collection using GC.Collect (). Be very careful when using this, as the complete collection may take some time. Best practice is simply to let the GC determine when is the best time to collect.

An object contains unmanaged resources but does not implement IDisposable? If so, this is a mistake.

, , , .

+9

"" - , , IDisposable. , , , , , .Net.

, , , , , . GC.Collect() — , , , .

+2

. , GC.Collect(), , . , .

, Dispose . . , Dispose StreamWriter Windows. .

Chris Sells .NET Rocks. , , , , .

http://www.dotnetrocks.com/default.aspx?showNum=10

:

Dispose Finalize # http://www.devx.com/dotnet/Article/33167/0/page/1

+2

, (, ).

0

.NET , , . , , .

. , . . Close - . , . Close Dispose , , , , , , , , .

0

BEWARE: f f g g entaation , GC.Collect() IDisposal , (LOH ~ 80kb +, ), (OOM) MB . , , , , , (80 kb) LOH, , parallelism - ( , , ), .

( - , - "% , , - .

System.Collections.Concurrent.ObjectPool beta1 ( , , , , , / ?), , Func < > Get/Put helper . , .

, .NET 4 .ToArray() , .ToArray(T target).

Getting support for using SOS / windbg (.loadby sos mscoreei for CLRv4) to analyze this class of problems can help. Thinking about this, the current garbage collection system is more like recycling garbage (using the same physical memory), ObjectPool is similar to garbage recycling. If someone remembers 3 Rs, reducing memory usage is also a good idea, for performance: wink

-2
source

Source: https://habr.com/ru/post/1704748/


All Articles