Linked Questions

18 votes
4 answers
18k views

I'm learning C# coming from python and wish to know how the C# garbage collector works - I found that I understood a lot more about python once I figured out what it was doing behind the scenes, and ...
theheadofabroom's user avatar
5 votes
3 answers
3k views

In the book C# 5.0 in a Nutshell by Joseph Albahari I found this: using System; using System.Text; class Test { static void Main() { StringBuilder ref1 = new StringBuilder ("object"...
developer747's user avatar
  • 16.1k
9 votes
1 answer
1k views

From GC.KeepAlive() on MSDN: Code this method at the end, not the beginning, of the range of instructions where obj must be available. Why does it have such non-intuitive behavior?
Doug's user avatar
  • 6,460
5 votes
1 answer
5k views

I'm having an awful time with C# not freeing up memory for a large structure I'm holding in memory after I'm no longer referencing it. I've included some code below that showcases a similar problem ...
skippy10110's user avatar
1 vote
2 answers
5k views

I have the following class. public class Foo { private string _DirName; private FileStream _MyfileStream; public FileStream MyfileStream { get { return _MyfileStream; } ...
sujith karivelil's user avatar
7 votes
1 answer
2k views

I use dotMemory to profile my application and I noticed the below behavior: inside my code there are some points where I perform garbage collection manually by using GC.Collect(); GC....
Demarsch's user avatar
  • 1,479
-1 votes
1 answer
1k views

I wrote this code: dog joe = new dog(); WeakReference wr = new WeakReference(joe); if (wr.IsAlive) { Console.WriteLine("Yes,first time")...
Think's user avatar
  • 9
8 votes
2 answers
207 views

So I have this simply Bell class that I'm testing garbage collection on: public class Bell { public void Ring() { Console.WriteLine("Ding ding"); } } If I run this code segment ...
Christian M.P.'s user avatar
2 votes
2 answers
2k views

I've got a simple test code in Nunit+.net core 2.0 under VS2019: public class Tests { public static int i = 0; class First { ~First() { i += 1; ...
Troskyvs's user avatar
  • 8,247
2 votes
1 answer
2k views

I apologize if the answer to this question is trivial. But I still cannot figure out this by myself. How does the garbage collector in .NET identify what objects on the heap are garbage and what ...
Prashanth's user avatar
  • 2,442
1 vote
1 answer
1k views

I think I am missing something fundamental and hope you can help. Below code creates an object, removes the reference and call the garbage collector. My expectation was that SomeClass's finalizer ...
Johannes Schacht's user avatar
4 votes
1 answer
452 views

... and by different I don't mean performance, debug-ability candies and so on, I am meaning different programs (programs that for the same input gives different outputs). Take the following program: ...
Eric Javier Hernandez Saura's user avatar
-2 votes
2 answers
2k views

I have an application that do complex processing and creates too many objects, I want to free up the memory after the processing is complete. I'm currently calling GC.collect in my application in a ...
hakuna matata's user avatar
0 votes
1 answer
600 views

Hi everyone I'm making a C# WinForms application that searches for duplicate images in a directory. It starts by calling a constructor with every image in the directory. There is a lot of files in ...
Issung's user avatar
  • 442
0 votes
1 answer
122 views

How does the GC determines that it needs to deference a local object passed into a callback? See the comments below on the need of disposing an object that is no longer referenced in an async ...
Kwyjibo's user avatar
  • 63

15 30 50 per page
1
2 3 4 5
10