FullGC normaly pauses all Threads while running. Having two AppDomains, each running several threads. When GC runs, will all threads be paused, or only those of either one AppDomain?
Garbage collection then goes through the three phases: mark, sweep, and, if required, compaction.
. NET's garbage collector manages the allocation and release of memory for your application. Each time you create a new object, the common language runtime allocates memory for the object from the managed heap.
In the common language runtime (CLR), the garbage collector (GC) serves as an automatic memory manager. The garbage collector manages the allocation and release of memory for an application. For developers working with managed code, this means that you don't have to write code to perform memory management tasks.
In Java, garbage collection happens automatically during the lifetime of a program. This eliminates the need to de-allocate memory and therefore avoids memory leaks. Java Garbage Collection is the process by which Java programs perform automatic memory management.
Hard to answer, best thing to do is just test it:
using System; using System.Reflection; public class Program : MarshalByRefObject { static void Main(string[] args) { var dummy1 = new object(); var dom = AppDomain.CreateDomain("test"); var obj = (Program)dom.CreateInstanceAndUnwrap(Assembly.GetExecutingAssembly().FullName, typeof(Program).FullName); obj.Test(); Console.WriteLine("Primary appdomain, collection count = {0}, gen = {1}", GC.CollectionCount(0), GC.GetGeneration(dummy1)); Console.ReadKey(); } public void Test() { var dummy2 = new object(); for (int test = 0; test < 3; ++test) { GC.Collect(); GC.WaitForPendingFinalizers(); } Console.WriteLine("In appdomain '{0}', collection count = {1}, gen = {2}", AppDomain.CurrentDomain.FriendlyName, GC.CollectionCount(0), GC.GetGeneration(dummy2)); } }
Output:
In appdomain 'test', collection count = 3, gen = 2 Primary appdomain, collection count = 3, gen = 2
Good evidence that a GC affects all AppDomains on the default CLR host. This surprised me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With