Get rid of Garbage Collector?

Well, this is potentially a question about noob, but here.

Is it possible to overtake the garbage collector?

The reason I'm asking is because I have a recursive method that runs several times during an event in my application (by several I mean about 60 times per second, and this event continues for an indefinite time, even minutes), The problem is that in each cycle of the recursive method I create a rather complex object (TreeViewItem with some mods that we need for the project And another complex object that works like a DataContext for TreeViewItem), so I'm worried what are these TreeViewItems os ayutsya heap when running a recursive method, so when the garbage collector runs, it does not clean them; and perhaps the next time the recursive method starts, it will stack even more TreeViewItem and the garbage collector will never catch up.

The problem is that we have a memory leak and we are looking for the culprit.

Any helpful help

+3
source share
8 answers

No, you cannot leak the garbage collector by overloading it.

The way the garbage collector works actually allows you to deal fairly well with situations such as yours.

If you delete a link to a large complex of objects, it will not collect objects one at a time. He sees that none of the objects has any active links, and he will immediately collect a whole bunch of objects.

, , . , , , 90% , 90%. 10% .

- , , . , , .

+7

, "" , . , .

: , ? , .

, , GC.Collect(), , .


1

, , - , . , . , . , , . , , .

+4

?

, , , , , , .

, , ? , - Out Of Memory "".

+1

, , .Net - , ( ).

, WinForms, , , .

, . VB:

while true
   dim foo(4500000) as byte ' allocate 4.5 MB
   foo = nothing ' c# null - remove ref
end while

( , , GC Process Explorer), OutOfMemory. , GC, -, . , .

: , , x86, x64, ...

+1

, ; ; , ; , .NET Framework .

( ) (), ; .

0

GC , . , , , , ( ) , .

, , - ( ) .

, . , DataContext TreeViewItem? -, TreeView TreeViewItems , DataContext?

0

:

, , , , , OutOfMemoryException 1,5 ( ).

( , ), -, . , , .

0

"" , . , GC, , .

OutOfMemoryException , , , , . , , , , . , , , , .

. , , , . .

GC , ( gc), , .. , . - . , , , , , .

, , , - , , .

I used the Scitech memory profiler before and found this to be very useful. Other tools exist - dotTrace , Ant memory profiler, and more. I used several of them and found that the Scitech profiler was for the best. Probably all have trial periods! :)

0
source

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


All Articles