This set of 30 multiple-choice questions (MCQs) explores essential topics in C# memory management, including stack vs heap, garbage collection, memory leaks, resource management, and advanced topics like pointers and unsafe code. These MCQs aim to enhance your understanding of memory management and optimization techniques in C# programming.
Dispose patternasync/await patternusing Statement for Resource Managementusing statement in C# ensure?
IDisposable for the using statement to work effectively?
using statement goes out of scope?
Dispose method is called on itDispose method?
using statement?
Dispose patternfixed statement do in C# unsafe code?
| Qno | Answer (Option with Text) |
|---|---|
| 1 | A) Value types |
| 2 | B) Reference types (objects) |
| 3 | C) The value is copied to the new location |
| 4 | A) Faster memory allocation and deallocation |
| 5 | B) Memory allocation is slower compared to the stack |
| 6 | A) To manage the memory for the program |
| 7 | A) GC.Collect() |
| 8 | A) Generation 0 |
| 9 | B) When an object is no longer reachable |
| 10 | A) Long-lived objects |
| 11 | A) Not disposing of unmanaged resources |
| 12 | C) Releasing unmanaged resources explicitly |
| 13 | A) Using the Dispose pattern |
| 14 | A) Visual Studio Diagnostic Tools |
| 15 | A) To prevent unnecessary garbage collection |
| 16 | B) Automatic disposal of resources when they are no longer needed |
| 17 | C) Objects using unmanaged resources |
| 18 | B) The Dispose method is called on it |
| 19 | A) It must be called manually to free unmanaged resources |
| 20 | A) File streams |
| 21 | A) unsafe |
| 22 | A) Accessing memory directly via pointers |
| 23 | A) To point to a location in memory |
| 24 | B) Allow unsafe code in project settings |
| 25 | A) fixed |
| 26 | C) Direct memory access leading to security vulnerabilities |
| 27 | B) Reducing memory overhead in performance-critical applications |
| 28 | A) Prevents the garbage collector from moving the variable in memory |
| 29 | C) & (address-of operator) |
| 30 | B) Memory corruption and crashes |