-
"COM
Descriptor Directory" part of the PE is responsible whether executable
file is a managed application (contain not zero address) or not.
-
In
case of the COM interoperability default CLR version is loaded (no
selecting of the CLR version from the assembly that was used in
building).
-
GC gen0 threshold depends on the size of CPU cache.
-
GC ratio: 10 - 1. Each 10 collections in the Gen0 leads to the 1 in the Gen1 and so on.
-
updated LOH is GC'ed at every GC Gen2. Gen2 and LOG are collected together, if either one's threshold it exceeded. >>
-
Pointers to the object with Finalize() method are kept in the finalization queue table. During GC these object are copied into finalization reachable table and separate thread is spawned to call Finalize for each object only on at the next GC. Thus we need 2 GC to truly finalize object.
-
System
does not guarantees that Finalizers will be called in any particular
order; there is a time limit to run Finalizers in the end of app (thus
not all finalizers may be run); may not run if exception arise into
finalizer's list.
-
CLR does not make any guarantees that finalizers will be called. The reason is that only one finalizer thread is used. >>
-
Previous
to the .NET 2.0 all built assemblies considered to be x86 only. This
means that in x64/Itanium platform they will load in the WoW64.
-
The CLR threads are: obliged - main, debug, finalize; optional - concurrent GC, server GC, AppDomain unload helper, threadpool. >>
-
Don't forget to
unsubscribe events in the Dispose object of the user control, otherwise
it creates the memory leak - because event and user control holds
bidirectionally strong references
>>
-
Consider
using WeakEvent class, which wraps ordinary events - which are
bidirectional strong references between the event source and the
listener and as such can keep an object alive that otherwise should be
dead already. (Helps implement Observe pattern successfully)
- new All
new allocated objects live on the managed heap segments - chunk of
memory that the garbage collector reserve from the OS (via
VirtuallAlloc) on behalf of managed code. >>
- new If object is equal or more than 85,000 bytes it will be put on LOH segment;
- new Objects
in LOH are not compacting and not moving during GC (performance
limitations), they are only removed from there, albeit you still need
to pin LOH objects to make sure they don't move, because this behavior
could change in future.
- new It's best if you can allocate a pool of large object and reuse them, instead of allocating temporary once >>
-
AppDomain.Load
may inadvertently load assembly into the current domain, not the
designated (because types are marshaled by value).
-
Use Assembly.LoadFrom
carefully, because it could load assembly from GAC or other directory
rather than you specified, due to version policy and binding rules
(such concept as binding contexts).
-
Administrator's redirect binding settings have the higher priority, even if DisallowBindingRedirects domain property is specified manually.
-
The
version of the CLR used to build an assembly is recorded into assembly.
To get this info you need to read PE header, string is located in a CLR
meta data header size (generally 16 bytes) from meta data section.
-
Checking the existence of short WeakReference with IsAlive() method doesn't guarantee that the object won't be GCed after this check.
-
In .NET 2.0 WeakReference could be safely used in finalizers - it doesn't throw exceptions.
-
In .NET 1.1 when we could end up with InvalidOperationException exception that is thrown by IsAlive() call to the already finalized WR. >>
-
GC.KeepAlive()
collect object that is out of scope in the current block code, for
example in the sub-block that is beyond call. In this case in release
compiler optimize code and remove call to GC.KeepAlive(). Albeit in debug reference is extended to the end of enclosing method. >>
-
!Threads (SOS command) shows the list of threads in the internal CLR Thread Store structure that is used to keep system C++ threads that are mapped to the C# Threads. >>
-
To prevent domain unloading caused by exception .NET 2.0 CLR has flag >>
-
To disable GAC viewer shell extension, modify a registry value: [HLKM\Software\Microsoft\Fusion] sub-key, create a "DisableCacheViewer" DWORD value and set it to 1 >>(p. 77)
-
To maximize the speed of crossing the boundaries you need to enable the "Cross Domain FastPath". To do this you need to set "[LoaderOptimization(LoaderOptimization.MultiDomainHost)]" for the main method and put your contracts DLL into GAC
-
new
Avoid allocate many large object on
temporary basis. Because in this case only LOH is populated and
cleared,
and you could spend a lot of time running garbage collections. For
example the arrays are usually the LOH object. If elements of array are
reference-rich the cost is hight. If
the element doesn't contain any references, I wouldn't need to go
through the array at all. For example, if you use an array to store
nodes in a binary tree avoid using reference in array, and store index
of left and right node. In this case GC wouldn't need to look for all
related references. >>