{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

lect11 - Yin Lou CS 2026 Spring 2010 Concept of Threading...

Info iconThis preview shows pages 1–10. Sign up to view the full content.

View Full Document Right Arrow Icon
Yin Lou CS 2026, Spring 2010
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Concept of Threading Synchronization Unsafe code
Background image of page 2
Garbage Collection Memory Management
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Recall unmanaged code eg C: double* a = malloc(sizeof(double) * M * N); for(int i = 0; i < M*N; i++) { a[i] = i; } What’s wrong? memory leak: forgot to call free(A); common problem in C
Background image of page 4
Solution: no explicit malloc/free e.g. In Java/C# double[] a = new double[M*N]; for(int i = 0; i < M*N; i++) { a[i] = i; } A “Garbage Collector” tries to free memory Keeps track of used data somehow
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Can control the behavior of GC not recommend in general sometimes useful to give hints Some methods Collect Add/RemoveMemoryPressure ReRegisterFor/SuppressFinalize WaitForPendingFinalizers
Background image of page 6
protected virtual void Finalize() Finalizers are called nondeterministically You don't know exactly when will be called Before an object is freed up by garbage collector When GC.Collect method is called When CLR is shutting down Can be suppressed by GC.SuppressFinalize
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Finalizers cannot be overridden Called when object is being destroyed Used to free up resources tied to it Destructors are called bottom-up public class A { ~A() { Console.WriteLine (“Destroy A”); } } public class B : A { ~B() { Console.WriteLine (“Destroy B”); } } A a = new B(); //program then shuts down B's destructor is called first then A's
Background image of page 8
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 10
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}