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

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Yin Lou CS 2026, Spring 2010 Concept of Threading Synchronization Unsafe code Garbage Collection Memory Management 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 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 Can control the behavior of GC not recommend in general sometimes useful to give hints Some methods Collect Add/RemoveMemoryPressure ReRegisterFor/SuppressFinalize WaitForPendingFinalizers 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 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...
View Full Document

This document was uploaded on 03/15/2010.

Page1 / 26

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

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online