Desktop Application Desktop Application Performance 2 — Questions and Answers
Question 1: What is a 'memory profile' in the context of desktop application performance?
- A CPU cache configuration
- A snapshot of memory allocations that identifies leaks and high-usage areas (Correct answer)
- A graphics memory setting
- A user profile stored on disk
Correct answer: A snapshot of memory allocations that identifies leaks and high-usage areas
A memory profile captures heap allocation data over time, allowing developers to detect memory leaks, excessive allocations, and objects that are not being garbage collected.
Question 2: What is the benefit of using a thread pool in a desktop application?
- Eliminating the need for synchronization
- Reusing a fixed set of threads for multiple tasks to avoid the overhead of creating and destroying threads (Correct answer)
- Automatically distributing tasks across CPU cores without code changes
- Replacing async/await patterns
Correct answer: Reusing a fixed set of threads for multiple tasks to avoid the overhead of creating and destroying threads
Thread pools maintain pre-created threads, dispatching tasks to available workers and avoiding the expensive overhead of thread creation and teardown for each task.
Question 3: What causes 'GDI object leak' in a Windows desktop application?
- Not releasing GDI objects like pens, brushes, and bitmaps after use (Correct answer)
- Allocating too much heap memory
- Using too many UI controls on a form
- Running the application without administrator rights
Correct answer: Not releasing GDI objects like pens, brushes, and bitmaps after use
Windows has a per-process limit on GDI objects; if pens, brushes, fonts, or bitmaps created with GDI functions are not deleted after use, the application exhausts this limit and rendering fails.
Question 4: What is 'dirty region' rendering in desktop GUI frameworks?
- Rendering with low-quality settings for performance testing
- Only redrawing parts of the screen that have changed rather than the entire window (Correct answer)
- Clearing the screen before every frame
- Rendering to a hidden buffer before displaying
Correct answer: Only redrawing parts of the screen that have changed rather than the entire window
Dirty region (or invalidation) rendering tracks which screen areas need repainting and only redraws those regions, reducing CPU and GPU work per frame.
Question 5: How does connection pooling improve the performance of a desktop application accessing a database?
- Compresses SQL queries before sending them
- Reuses existing database connections instead of creating a new one for every query (Correct answer)
- Caches all query results locally
- Distributes queries across multiple database servers
Correct answer: Reuses existing database connections instead of creating a new one for every query
Opening a database connection is expensive; pooling maintains a set of open connections that are reused across queries, significantly reducing connection overhead.
Question 6: What does 'ahead-of-time (AOT) compilation' offer for desktop application startup performance?
- Compiles code at runtime for better optimization
- Pre-compiles code to native instructions before deployment, eliminating JIT overhead at startup (Correct answer)
- Reduces the size of configuration files
- Moves compilation to a cloud server
Correct answer: Pre-compiles code to native instructions before deployment, eliminating JIT overhead at startup
AOT compilation produces native machine code before deployment so the application starts immediately without waiting for a JIT compiler to translate IL or bytecode at runtime.
What is a 'memory profile' in the context of desktop application performance?