Heap Management slide I
Heap Mana gement slide 1
Quote of the day "Manually managing blocks of memory in C is like juggling bars of soap in a prison shower: It's all fun and games until you forget about one of them.” Unknown slide2
Quote of the Day “Manually managing blocks of memory in C is lik j li b f i i h like juggling bars of soap in a prison shower: It's all fun and games until you forget about one ofh ” t em. - Unknown slide 2
Major Areas of Memory ●Static area Fixed size,fixed content,allocated at compile time ·Run-time stack Variable size,variable content(activation records) -Used for managing function calls and returns ·Heap Fixed size,variable content Dynamically allocated objects and data structures Examples:ML reference cells,malloc in C,new in Java slide 3
Major Areas of Memory • Static area – Fixed size, fixed content, allocated at compile time • Run-time stack – Variable size, variable content (activation records) – Used for managing function calls and returns • Heap – Fixed size variable content Fixed size, variable content – Dynamically allocated objects and data structures • Examples: ML reference cells, malloc in C, new in Java slide 3
Heap Storage Memory allocation under explicit programmatic control -C malloc,C++/Pascal Java/C#new operation. Memory allocation implicit in language constructs -Lisp,Scheme,Haskel,SML,..most functional languages Autoboxing/unboxing in Java 1.5 and C# Deallocation under explicit programmatic control -C,C++,Pascal Deallocation implicit Java,C#,Lisp,Scheme,Haskel,SML
Heap Storage • Memory allocation under explicit programmatic control – C malloc, C++ / Pascal / Java / C# new operation. • Memory allocation implicit in language constructs – Lisp, Scheme, Haskel, SML, … most functional languages – Autoboxing/unboxing in Java 1.5 and C# • Deallocation under explicit programmatic control – C, C++, Pascal • Deallocation implicit – Java, C#, Lisp, Scheme, Haskel, SML, …
Heap Storage Deallocation Explicit versus Implicit Deallocation In explicit memory management,the program must explicitly call an operation to release memory back to the memory management system. In implicit memory management,heap memory is reclaimed automatically by a "garbage collector". Examples: Implicit:Java,Scheme Explicit:Pascal and C To free heap memory a specific operation must be called. Pascal ==dispose C ==free C++==delete Implicit and Explicit:Ada Deallocation on leaving scope
Heap Storage Deallocation Explicit versus Implicit Deallocation In explicit memory management, the program must explicitly In explicit memory management, the program must explicitly call an operation to release memory back to the memory management system. In implicit memory management, heap memory is reclaimed automatically by a “garbage collector”. Examples: • Implicit: Java, Scheme • Explicit: Pascal and C Explicit: Pascal and C To free heap memory a specific operation must be called. Pascal ==> dispose C == > free C++ ==> delete • Implicit and Explicit: Ada Deallocation on leaving scope